Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For starters, both calls (require_once and include_once) double-check if a file has not been included before.</p> <p>So the way they both achieve this is by searching the file in all available paths and by essentially checking if it hasn't been in the mix before etc..</p> <p>In the background what happens is that they evaluate all the different options (e.g. multiple include_path's, etc.) and then by creating the <em>realpath</em> from this abreviated form they create a unique identifier. There is only one and the same path - not two.</p> <p>This is already not the fastest process on the planet and generally happens on each request with PHP. Then add another expensive operation which is the stat when it creates what I called the <em>realpath</em> (realpath, because it's sort of what <a href="http://php.net/realpath" rel="nofollow noreferrer">realpath()</a> does) to check if the file exists.</p> <p>Correct me if I am wrong, but APC has optimizations especially for this case.</p> <p>So anyway - now <strong>on to the difference</strong> between require_once and include_once, which is that require_once evaluates the file (for <em>low-level</em> parse errors, etc.) when it includes it. This is an additional check which you can get rid of if you have enough QA in place that a parse error can never sneak into an include.</p> <p>It's just tricky to find otherwise. :-)</p> <p>(Something to consider: You could develop with require_once and replace all calls with include_once when you deploy.)</p> <p>As for an opcode cache - I'd recommend <a href="http://pecl.php.net/apc" rel="nofollow noreferrer">APC</a>. It's been discussed on stackoverflow before. Personally, I am/we are using it for a while (we handle roughly 100k visitors/day with 3 frontends and 1 backend) and we are very happy. APC is also optimized for the require_once/include_once madness.</p> <p>A pretty cool side-effect is that APC also allows you to store PHP variables in memory - sort of persistant, etc..</p> <p>A couple additional pointers:</p> <ol> <li>A lot of people claim to speed up any application with <a href="http://php.net/autoload" rel="nofollow noreferrer">__autoload</a>.</li> <li>With an opcode cache, avoid conditional require_once/include_once (e.g. in loops or in control-flow).</li> <li>Some people say that /absolute/path/to/file.php in include_ or require_once is faster than relying on the include_path.</li> <li>The order of the paths in your include_path matters as well.</li> </ol> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload