note 118695 added to class.recursivedirectoryiterator
| From: | alexandrebratgmaildotcom | Date: | Wed, 20 Jan 2016 14:50:04 +0000 |
| Subject: | note 118695 added to class.recursivedirectoryiterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204734@lists.php.net to get a copy of this message | ||
I tried to use RecursiveDirectoryIterator to dump all files (and theirs properties, such as
size/is_link/is_dir/mtime/perms/owner/group) from a large directory (~400.000 files), filtering some
specific wanted files/folders.
Using RecursiveDirectoryIterator and SplFileInfo, dump was taking about 50 seconds to perform, but
it was working.
However, to improve performance, I decided to make another version of the same script, using only
direct file functions, such as "readdir", "filesize", "filemtime",
etc.., and adding recursivity myself (if(is_dir($path)) doRecursivity($path);
After running it, script went from ~50s to only ~20s to complete (On Linux CentOS 7, SSD 300IPs).
Strangely, on Windows 7, Sata3 (with exactly same files [mirrored]) the time went from ~63s to ~57s.
I believe that this payload is due to the OO approach of SPL, which runs lots of unnecessary extra
code to perform the same tasks with more reliability, while direct file funcions are more like alias
to C corresponding functions, and thereover, must faster.
So, if you're dealing with a large amount of files, using RecursiveDirectoryIterator is
probably not the way to go.
----
Server IP: 72.52.91.14
Probable Submitter: 177.40.76.251
----
Manual Page -- http://php.net/manual/en/class.recursivedirectoryiterator.php
Edit -- https://master.php.net/note/edit/118695
Del: integrated -- https://master.php.net/note/delete/118695/integrated
Del: useless -- https://master.php.net/note/delete/118695/useless
Del: bad code -- https://master.php.net/note/delete/118695/bad+code
Del: spam -- https://master.php.net/note/delete/118695/spam
Del: non-english -- https://master.php.net/note/delete/118695/non-english
Del: in docs -- https://master.php.net/note/delete/118695/in+docs
Del: other reasons-- https://master.php.net/note/delete/118695
Reject -- https://master.php.net/note/reject/118695
Search -- https://master.php.net/manage/user-notes.php