php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51262 RecursiveDirectoryIterator sucks performance
Submitted: 2010-03-10 14:36 UTC Modified: 2020-05-03 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: h dot reindl at thelounge dot net Assigned:
Status: No Feedback Package: SPL related
PHP Version: 5.3.2 OS: win32 only
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: h dot reindl at thelounge dot net
New email:
PHP Version: OS:

 

 [2010-03-10 14:36 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-10 22:09 UTC] jani@php.net
-Operating System: Windows +Operating System: win32 only
 [2011-11-16 13:54 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: colder
 [2017-10-24 07:25 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: colder +Assigned To:
 [2020-04-22 07:32 UTC] alexinbeijing at gmail dot com
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.
 [2020-04-22 07:36 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2020-04-22 07:36 UTC] requinix@php.net
Can anyone reproduce the behavior described in the report?
 [2020-05-03 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2020-05-03 05:09 UTC] bugreports at gmail dot com
> The OP would have done well to try commenting out the entire body 
> of `foreach` to see if something in the body was slow

the OP is not an idiot that he removes something from a working example where you just need to created many thousand files in many thousand folders

it's likely windows and iTäs braindead filesystem and caching which we no longer support (way too much bordercase with damned backslahses here and there)

i would encourage the PHP project to do the same - there is no reason in 2020 with virtualization, containers and WSL for the maintainance burden compared back in the days where the windows binaries where the entry point for developers
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC