#35997 [NEW]: FilterIterator on DirectoryIterator never releases file handle
| From: | rquadling at gmail dot com | Date: | Fri, 13 Jan 2006 15:52:12 +0000 |
| Subject: | #35997 [NEW]: FilterIterator on DirectoryIterator never releases file handle | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-91851@lists.php.net to get a copy of this message | ||
From: rquadling at gmail dot com
Operating system: Windows XP SP2
PHP version: 5.1.2
PHP Bug Type: SPL related
Bug description: FilterIterator on DirectoryIterator never releases file handle
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 bug report at http://bugs.php.net/?id=35997&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35997&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35997&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35997&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=35997&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35997&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35997&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35997&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35997&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35997&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35997&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35997&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35997&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35997&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35997&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35997&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35997&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35997&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35997&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35997&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35997&r=mysqlcfg