#35997 [Opn->Asn]: FilterIterator on DirectoryIterator never releases file handle
| From: | tony2001@php.net | Date: | Fri, 13 Jan 2006 16:48:52 +0000 |
| Subject: | #35997 [Opn->Asn]: FilterIterator on DirectoryIterator never releases file handle | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-91856@lists.php.net to get a copy of this message | ||
ID: 35997
Updated by: tony2001@php.net
Reported By: rquadling at gmail dot com
-Status: Open
+Status: Assigned
Bug Type: SPL related
Operating System: Windows XP SP2
PHP Version: 5.1.2
-Assigned To:
+Assigned To: helly
New Comment:
Assigned to the maintainer.
Previous Comments:
------------------------------------------------------------------------
[2006-01-13 16:52:10] rquadling at gmail dot com
Description:
------------
Using a FilterIterator on a DirectoryIterator does not close the handle
of the directory being iterated.
If I do not use a FilterIterator and process the files manually from
the DirectoryIterator, the handle is released.
To see this in action ...
Place a bunch of CSV files in the C:\TEMP directory and create a
C:\TEMP\JUNK directory.
The code below will loop until it has 1000 CSV files.
Using System Internals Process Explorer you can see that the number of
handles used by php.exe goes up and up and up.
I have several programs which loop over a directory repeatedly. I have
stopped using the FilterIterator and use just a DirectoryIterator and
then manually filter the filenames.
Reproduce code:
---------------
<?php
class FileTypeList extends FilterIterator
{
protected
$s_Type;
function __construct($s_Path, $s_Type)
{
$this->s_Type = $s_Type;
parent::__construct(new DirectoryIterator($s_Path));
}
function accept()
{
$b_Result = (strcasecmp($this->s_Type, pathinfo($this->current(),
PATHINFO_EXTENSION)) !== 0);
return $b_Result;
}
}
$am_Files = array();
while(count($am_Files) < 1000)
{
echo "Looking\n";
foreach(new FileTypeList('C:\\TEMP', 'CSV') as $o_FILE)
{
if ($o_FILE->isFile())
{
$s_FileName = str_replace('/', DIRECTORY_SEPARATOR,
$o_FILE->getPathname()); // Directory separator required for windows
filenames.
$am_Files[] = array
(
'Modified' => filemtime($s_FileName),
'Name' => $s_FileName,
);
rename($s_FileName, 'C:\\TEMP\\JUNK\\' . basename($s_FileName));
echo "Found $s_FileName\n";
}
}
}
print_r($am_Files);
?>
Expected result:
----------------
File handles to open and close as required.
Actual result:
--------------
File handles are opened and stay open. System resources get used up.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35997&edit=1