Is it possible to speed up a recursive file scan in PHP? Is it possible to speed up a recursive file scan in PHP? php php

Is it possible to speed up a recursive file scan in PHP?


I'm not sure if the performance is better, but you could use a recursive directory iterator to make your code simpler... See RecursiveDirectoryIterator and 'SplFileInfo`.

$it = new RecursiveDirectoryIterator($from);foreach ($it as $file){    if ($file->isDot())        continue;    echo $file->getPathname();}


Before you start changing anything, profile your code.

Use something like Xdebug (plus kcachegrind for a pretty graph) to find out where the slow parts are. If you start changing things blindly, you won't get anywhere.

My only other advice is to use the SPL directory iterators as posted already. Letting the internal C code do the work is almost always faster.


PHP just cannot perform as fast as C, plain and simple.