Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>require_once</code> and <code>include_once</code> both require that the system keeps a log of what's already been included/required. Every <code>*_once</code> call means checking that log. So there's definitely <em>some</em> extra work being done there but enough to detriment the speed of the whole app?</p> <p>... I really doubt it... Not unless you're on <em>really</em> old hardware or doing it a <em>lot</em>.</p> <p>If you <em>are</em> doing thousands of <code>*_once</code>, you could do the work yourself in a lighter fashion. For simple apps, just making sure you've only included it once <em>should</em> suffice but if you're still getting redefine errors, you could something like this:</p> <pre><code>if (!defined('MyIncludeName')) { require('MyIncludeName'); define('MyIncludeName', 1); } </code></pre> <p>I'll personally stick with the <code>*_once</code> statements but on silly million-pass benchmark, you can see a difference between the two:</p> <pre><code> php hhvm if defined 0.18587779998779 0.046600103378296 require_once 1.2219581604004 3.2908599376678 </code></pre> <p>10-100× slower with <code>require_once</code> and it's curious that <code>require_once</code> is seemingly slower in <code>hhvm</code>. Again, this is only relevant to your code if you're running <code>*_once</code> thousands of times.</p> <hr> <pre><code>&lt;?php // test.php $LIMIT = 1000000; $start = microtime(true); for ($i=0; $i&lt;$LIMIT; $i++) if (!defined('include.php')) { require('include.php'); define('include.php', 1); } $mid = microtime(true); for ($i=0; $i&lt;$LIMIT; $i++) require_once('include.php'); $end = microtime(true); printf("if defined\t%s\nrequire_once\t%s\n", $mid-$start, $end-$mid); </code></pre> <hr> <pre><code>&lt;?php // include.php // do nothing. </code></pre>
    singulars
    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