ID:               42679
 Updated by:       [EMAIL PROTECTED]
 Reported By:      nangnahz at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Performance problem
 Operating System: Ubuntu 7.04
 PHP Version:      5.2.4
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

scandir() does a lot more then readdir


Previous Comments:
------------------------------------------------------------------------

[2007-09-15 22:45:10] nangnahz at gmail dot com

Description:
------------
I try to traversal a directory. Include about 20000 files and 200
directories.

Use scandir function, it cost about 70 seconds.

Then I use readdir function, it cost only 6 seconds!



System Version:
Linux ubuntu 2.6.20-16-generic
Apache/2.2.6
PHP/5.2.4
Mysql/5.0.45




Reproduce code:
---------------
<?php
function useScandir($dir) {
        $i = 0;
        while ($dir) {
                foreach (scandir($dir[0]) as $filename) {
                        if ($filename != '.' && $filename != '..') {
                                $filename = $dir[0] . '/' . $filename;
                                if (is_dir($filename)) {
                                        echo $i . " [dir] " . $filename . 
"<br>";
                                        $dir[] = $filename;
                                } else {
                                        echo $i . " file: " . $filename . 
"<br>";
                                }
                                $i++;
                        }
                }
                array_shift($dir);
        }
}
useScandir(array ("/data/www/manual"));
?>

<?php
function useReaddir($dir) {
        $i = 0;
        while ($dir) {
                $dh = opendir($dir[0]);
                while (false !== ($filename = readdir($dh))) {
                        if ($filename != '.' && $filename != '..') {
                                $filename = $dir[0] . "/" . $filename;
                                if (is_dir($filename)) {
                                        echo $i . " [dir] " . $filename . 
"<br>";
                                        $dir[] = $filename;
                                } else {
                                        echo $i . " file: " . $filename . 
"<br>";
                                }
                                $i++;
                        }
                }
                closedir($dh);
                array_shift($dir);
        }
}
useReaddir(array ('/data/www/manual'));
?>

Expected result:
----------------
run fast!!!

Actual result:
--------------
it's very slow......


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42679&edit=1

Reply via email to