note 77136 deleted from function.include by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 00:58:24 +0000 |
| Subject: | note 77136 deleted from function.include by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155456@lists.php.net to get a copy of this message | ||
Note Submitter: eeckart at gmail dot com
----
In reference to the fopen() and $use_include_path workaround for checking whether a include file
exists as posted by [arnold at bean-it dot nl]...
I did some benchmarks with 100 dirs (each with 1 file) in the include_path on Apache/2.0.55 (Win32)
PHP/5.2.1.
Here are the results:
(note: in the success scenarios, I am include'ing the file in the LAST directory on the include
stack. This is to maximize the seek time; fail scenarios simply use a non-existent file; all times
are in seconds )
benchmarks --> plain vanilla INCLUDE
(success)
0.05515718460083
0.054859161376953
0.053768157958984
(fail)
0.22402501106262
0.17378783226013
0.14510798454285
benchmarks --> fopen() and $use_include_path workaround
(success)
0.060588836669922
0.069549798965454
0.056423902511597
(fail)
0.05295991897583
0.039775133132935
0.054499864578247
>>> CONCLUSION
In cases involving MANY include paths, include() is -marginally- faster than the workaround
(unsurprising - we incur the extra overhead of BOTH the fopen() call AND the $use_include_path
seek). I say marginal in comparison to the "fail" scenarios, detailed next..
The most surprising thing is the inefficiency of include() when you are trying for a non-existent
file. As compared to the workaround, the native include() method is roughly 3 times slower.
Based on additional tests (50 paths only), I note that any decrease in seek time for either case is
generally linear to the number of paths.
---
THEREFORE, depending on the amount of paths you have, you might want to resort to different methods
of optimizing the includes in your scripts, especially if you need to constantly test for the
existence of include'd files (our organization uses a templating engine that relies on a
virtual flat directory structure using the set_include_path() function).
---
From a technical perspective, I have no idea why this is the case and I find the prospect of
trawling the PHP source to be rather daunting. However, as an educated guess: I figure that the
include() code assumes the file exists, and so wastes processor cycles making a system read call,
which inevitably fails.
For those interested in the benchmark script, you can email me at the email address provided above.
No support, of course. :P