A somewhat faster alternative to is_dir and is_file?
| From: | Wouter van Vliet | Date: | Thu, 09 Sep 2004 09:32:43 +0000 |
| Subject: | A somewhat faster alternative to is_dir and is_file? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-196199@lists.php.net to get a copy of this message | ||
Howdy,
I've written some, kinda coolish, class that reads directories
recursively with some simple calls. Yihaaa, .. (but I'm not the only
one who has done that, I guess :P). Anyway, during the process of
traversing a directory it checks to see if the "something" that was
found is either a directory or a file, based on that it will do some
things. Fine, works.
But, now that I've got a directory with about 800 files to read I
noticed that it takes the poor script almost two seconds to find the
correct type of all the "somethings". In fact, I timed it on a steady
1.71.
I've tried to use filetype() on the "something", but that took even
longer - while looping through the directory without any checks
finishes in 0.01 seconds.
Now, for the question: does anybody know an alternative method on
checking whether a "something" is either file or directory?
Wouter
(this time, I'm on a Windows XP machine running PHP5 - just tested the
same thing on Linux and PHP 4.3.8 and came out on 0.63 secs, ..)