stat functions do each path component?
| From: | Scott Nichol | Date: | Thu, 07 Oct 2010 18:09:11 +0000 |
| Subject: | stat functions do each path component? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-49885@lists.php.net to get a copy of this message | ||
In comparing the performance of PHP 5.2.5 file_exists calls versus C stat calls, I discovered via
Windows sysinternals
ProcessMonitor that PHP seems to do a stat on each component of a file path. For example,
file_exists("e:\\wamp\\www\\ra-v2\\system\\application\\libraries\\MY_Controller.php")
appears to stat "E:\wamp", "E:\wamp\www",
etc., finally getting to the file. That compares to doing _stat64 of
"e:\\wamp\\www\\ra-v2\\system\\application\\libraries\\MY_Controller.php" in C, which just
does the stat on the file. The timings
from my tests show the C app finishing in about one-seventh the time, which is what I would expect
from the PHP code doing seven
times as many stat calls.
Assuming my inference about all the stat calls is correct, is there a rationale for this? If the
PHP app I am working on made just
a couple of file_exists calls, I would not bother to ask, but it uses the CodeIgniter framework
which is doing >100 file_exists
calls for each page being accessed, so the affect is very noticeable.
FYI, I poked around the PHP SVN web interface for a while and found php_check_open_basedir_ex called
in plain_wrapper.c, which I
suspect causes the calls, but ran out of steam before confirming the cause of the behavior.
TIA
--
Scott Nichol