From: sprice at wisc dot edu
Operating system: Mac OS X 10.3.4
PHP version: 4.3.7
PHP Bug Type: Performance problem
Bug description: include_once() and require_once() could be *much* faster
Description:
------------
I use include_once() and require_once() quite a bit, as
I would guess many others do. During a single page load,
I might call for the same file from many functions, just
to make sure things get defined correctly and in the
correct order. I did some testing today, and I noticed
that they both could be close to *two orders of
magnitude* faster for multiple inclusions.
I have attached the PHP code that I used to test this.
On my computer, when I use include_once() inside the for
loop, it takes about 6.0 seconds. When I use
improved_include_once(), it takes about 0.08 seconds.
The same goes for require_once().
Could/Should something like this be implemented in PHP?
It seems like a good idea, and you guys could do a more
efficient implementation than I am able to do.
Reproduce code:
---------------
function getMicroTime(){
list($usec, $sec) = explode( ' ', microtime() );
return ((float)$usec + (float)$sec);
}
function improved_include_once($filename){
if(!isset($GLOBALS['included_files'][$filename])){
include_once($filename);
$GLOBALS['included_files'][$filename] = TRUE;
}
}
$start_time = getMicroTime();
for($i = 0; $i < 10000; $i++){
include_once('my_file.inc');
}
echo (getMicroTime() - $start_time);
--
Edit bug report at http://bugs.php.net/?id=28901&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28901&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28901&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28901&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28901&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28901&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28901&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28901&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28901&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28901&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28901&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28901&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28901&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28901&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28901&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28901&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28901&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28901&r=float