#18683 [Ana]: Performance boost of require()
| From: | tiele at staff dot start dot be | Date: | Thu, 01 Aug 2002 17:01:24 +0000 |
| Subject: | #18683 [Ana]: Performance boost of require() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-15753@lists.php.net to get a copy of this message | ||
ID: 18683
User updated by: tiele@staff.start.be
Reported By: tiele@staff.start.be
Status: Analyzed
Bug Type: Feature/Change Request
Operating System: Unix
PHP Version: 4.2.1
New Comment:
And how right you are...
What i've done now is the following:
function runtemplate($file) {
$file = realpath($file);
global $V;
if(!function_exists($V[$file])) {
$fd = fopen ($file, "r");
$V[$file] = fread($fd, filesize($file));
$V[$file] = "?>".$V[$file]."<?";
$V[$file] = create_function( "", $V[$file] );
fclose ($fd);
echo "<td>written as function</td>";
}
$V[$file]();
}
This way i can still call my function with the filename, only has to be
opened once and only has to be compile once.
1000x require takes 0.49168002605438 seconds
1000x evaluate takes 0.14559996128082 seconds
1000x running as a function takes 0.038320064544678 seconds !!
Thx !
Is there a way i can change my note that i've posted on php.net ? The
note i've written is now completely bogus.
Previous Comments:
------------------------------------------------------------------------
[2002-08-01 11:13:39] rasmus@php.net
Wouldn't it make more sense to simply require the file once, but in the
required file, put whatever it is the file does inside a function.
Then call that function 1000 times. It would seem to me that this is
exactly the functionality you are looking for.
------------------------------------------------------------------------
[2002-08-01 10:38:53] nohn@php.net
I think the best thing would be storting this in SRM (www.vl-srm.net)
------------------------------------------------------------------------
[2002-08-01 10:19:01] tiele@staff.start.be
Hey, this is not a real feature request or a bug... just something
that came to my attention when benchmarking my script. I have added a
note on the require() page with the script and some explination.
I have a script that requires the use of other php scripts. Some of
them over a 1000 times (think of a template for a hyperlink). Normally
i would 'require' this file 1000 times but when thinking this over,
this would mean that there would be 1000 times disk activity.
When storing the contents of that other php script into a string and
evaluating this 1000 times i noticed this was 10 to 100 times faster.
Perhaps it would be possible to either adjust the require() function or
to add require_stick() that would hold this template in it's memory
until the main script is done or some flush is done.
Just trying to put out a helping hand. Keep it up !
Greets from belgium,
Tiele
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18683&edit=1