Skip to end of metadata
Go to start of metadata

<p>In order to get the fastest possible loading of includes, you should ensure that in situations where you have multiple include paths, the paths are in the order of how many files you wish to include (most first).</p>

<p>In most Zend Framework applications, the majority of the included files will be classes from the Zend Framework library, and you should therefore ensure that the Zend Framework path is the first in your include path list.</p>

<p>To do this, add the path like so:</p>

<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
set_include_path($path . PATH_SEPARATOR . get_include_path());

<p>The reason for this is that when including files, PHP will look in each path for the file requested, in the order specified in the include path list. If 90% of your files are Zend Framework classes, but you've got a couple of other paths before the Zend Framework path, PHP will waste a lot of time looking in those first, for every Zend Framework class.</p>

<p>This can have a significant performance impact. I saw an improvement of ~32% (~120ms) by changing my include path from:</p>

<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
.;X:\Custom Library 1\;X:\Custom Library 2\;X:\Zend Framework


<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
X:\Zend Framework;X:\Custom Library 1\;X:\Custom Library 2\;.

<p>The only downside of this is that files included from paths at the end of the list will take longer, but that's basically irrelevant, because something has to come last, so it may as well be the least used paths.</p>

<p>Of course, you should always try to keep your include path list as short as possible as well.</p>

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jul 22, 2008

    <p>A script like this will compile all ZF source to APC (to run before opening trafic to the servers)</p>

    <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
    class MyFilterIterator extends FilterIterator
    public function accept()

    Unknown macro: { return (substr($this->current(),-3) == 'php'); }

    $rdi = new RecursiveDirectoryIterator('/ZFPath/');
    $rii = new RecursiveIteratorIterator($rdi,RecursiveIteratorIterator::LEAVES_ONLY);
    foreach(new MyFilterIterator($rii) as $file) {