php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #18683 Performance boost of require()
Submitted: 2002-08-01 10:19 UTC Modified: 2002-08-01 13:31 UTC
From: tiele at staff dot start dot be Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.2.1 OS: Unix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tiele at staff dot start dot be
New email:
PHP Version: OS:

 

 [2002-08-01 10:19 UTC] tiele at staff dot start dot 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-01 10:38 UTC] nohn@php.net
I think the best thing would be storting this in SRM (www.vl-srm.net)
 [2002-08-01 11:13 UTC] 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 13:01 UTC] tiele at staff dot start dot be
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.
 [2002-08-01 13:31 UTC] nohn@php.net
Done this for you ;)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 14:01:30 2024 UTC