Bug #51262 [Com]: RecursiveDirectoryIterator sucks performance
| From: | alexinbeijing at gmail dot com | Date: | Wed, 22 Apr 2020 07:32:19 +0000 |
| Subject: | Bug #51262 [Com]: RecursiveDirectoryIterator sucks performance | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226713@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=51262&edit=1
ID: 51262
Comment by: alexinbeijing at gmail dot com
Reported by: h dot reindl at thelounge dot net
Summary: RecursiveDirectoryIterator sucks performance
Status: Open
Type: Bug
Package: SPL related
Operating System: win32 only
PHP Version: 5.3.2
Block user comment: N
Private report: N
New Comment:
Don't have a Windows machine readily available or I would try this out.
The OP would have done well to try commenting out the entire body of
foreach to see if
something in the body was slow, or whether it was just the process of iterating through the
directories and files.
Previous Comments:
------------------------------------------------------------------------
[2010-03-10 14:36:58] h dot reindl at thelounge dot net
Description:
------------
On Linux it is really easy to read recursive folder-listings with SPL even if there are many files
and folders, i need here between 1 and 3 seconds after cold start of the machine on my fedora-box
On Windows the same needs between 180 and 240 seconds and "process explorer" shows > 1
MB I/O the whole time, same script, same folders contents, same php-version
WHAT do you do on windows?
Are you reading all the 30.000 files instead listing them only?
Test script:
---------------
<?php
$files = array();
$folders = array();
$spl_objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::CHILD_FIRST);
try
{
foreach($spl_objects as $filename=>$spl_object)
{
if(DIRECTORY_SEPARATOR === "\\")
{
$filename = str_replace(DIRECTORY_SEPARATOR, '/', $filename);
}
if(substr($filename, 0, 2) === './')
{
$filename = substr($filename, 2);
}
switch($spl_object->isDir())
{
case false: $files[$filename] = $spl_object->getMTime(); break;
case true: $folders[] = $filename; break;
}
}
}
catch(UnexpectedValueException $e)
{
error_log('Directory "' . $path . '" contained a directory we can not
recurse into');
return false;
}
sort($folders);
ksort($files);
$enumerate_list = array('files'=>$files, 'folders'=>$folders);
unset($folders);
unset($files);
?>
Expected result:
----------------
a normal performance
Actual result:
--------------
waiting minutes to get hughe folder-listings
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=51262&edit=1