<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>ingo() -&gt; tech. % Ingo Schramm - PHP</title>
    <link>http://www.ingo-schramm.de/blog/</link>
    <description>Share experience in web development</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <pubDate>Mon, 11 May 2009 11:36:16 GMT</pubDate>

    <image>
        <url>http://www.ingo-schramm.de/blog/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: ingo() -&gt; tech. % Ingo Schramm - PHP - Share experience in web development</title>
        <link>http://www.ingo-schramm.de/blog/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>PHP array_shift() does not scale</title>
    <link>http://www.ingo-schramm.de/blog/archives/9-PHP-array_shift-does-not-scale.html</link>
            <category>PHP</category>
            <category>Scalability</category>
    
    <comments>http://www.ingo-schramm.de/blog/archives/9-PHP-array_shift-does-not-scale.html#comments</comments>
    <wfw:comment>http://www.ingo-schramm.de/blog/wfwcomment.php?cid=9</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.ingo-schramm.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=9</wfw:commentRss>
    

    <author>nospam@example.com (Ingo)</author>
    <content:encoded>
    Arrays are at the core of PHP and act as the swiss army knife for data structures. They are known as an efficient and generic solution. But this is only half of the truth. The internal C representation as a hash table causes a non-intuitive performance behaviour of arrays. Associative arrays for example scale badly in key size and the different accessing functions like array_pop() and array_shift() behave very differently in respect to performance. I made a quick benchmark to visualize the difference. At least in loops it is more efficient to reverse the array and pop it instead of simply shifting it. This is because an array_shift() - strange enough - forces a reindexing operation for each shift.&lt;br /&gt;
&lt;br /&gt;
&lt;!-- s9ymdb:1 --&gt;&lt;a href=&quot;http://www.ingo-schramm.de/blog/uploads/pop_vs_shift2.png&quot;&gt;&lt;img class=&quot;serendipity_image_center&quot; width=&quot;110&quot; height=&quot;82&quot; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://www.ingo-schramm.de/blog/uploads/pop_vs_shift2.serendipityThumb.png&quot; alt=&quot;&quot; target=&quot;_new&quot;/&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
This blog post is an appendix to another blog post I wrote about &lt;a href=&quot;http://developer.studivz.net/2009/03/18/php-spl-data-structures-benchmark/&quot; title=&quot;Benchmarking SPL Data Structures&quot;&gt;benchmarking SPL data structures&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Fri, 27 Mar 2009 11:39:24 +0100</pubDate>
    <guid isPermaLink="false">http://www.ingo-schramm.de/blog/archives/9-guid.html</guid>
    
</item>
<item>
    <title>PHP Myth: static function call faster than instance function call</title>
    <link>http://www.ingo-schramm.de/blog/archives/4-PHP-Myth-static-function-call-faster-than-instance-function-call.html</link>
            <category>PHP</category>
            <category>Scalability</category>
    
    <comments>http://www.ingo-schramm.de/blog/archives/4-PHP-Myth-static-function-call-faster-than-instance-function-call.html#comments</comments>
    <wfw:comment>http://www.ingo-schramm.de/blog/wfwcomment.php?cid=4</wfw:comment>

    <slash:comments>490</slash:comments>
    <wfw:commentRss>http://www.ingo-schramm.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=4</wfw:commentRss>
    

    <author>nospam@example.com (Ingo)</author>
    <content:encoded>
    There exist a reasonable number of myths about PHP. One I will challenge today. If you ask an average PHP programmer whether a static function call or a function call on an instance performs better he or she will problably say - without thinking - static. This is wrong.&lt;br /&gt;
&lt;br /&gt;
Sure, if you want to call a method on an instance you first have to instantiate that instance. This takes some time by its own. The sum of CPU time for instantiation and a single method call is in fact greater than the CPU time needed to call a static function. So, if you ask for the time of single calls you will support the myth. But the question is wrong.&lt;br /&gt;
&lt;br /&gt;
In real life you will never do isolated calls. The question of interest is not how a single call performs but how the different kinds of method calls &lt;u&gt;scale&lt;/u&gt;. If you measure this you will get a different picture. The instance calls scale definitely better. If you even have just a handful of static method calls on a class the same calls on an instance - a singleton for example - will save you time. &lt;br /&gt;
&lt;br /&gt;
The image below shows a measurement with empty methods and light weight classes on PHP 5.2.5. The point where the two lines are crossing may vary with the complexity of your class.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;/img/static_vs_instance.png&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;/img/thumbs/static_vs_instance.png&quot; alt=&quot;PHP static call vs. instance call&quot; border=&quot;0&quot;/&gt;&lt;/a&gt; 
    </content:encoded>

    <pubDate>Tue, 18 Nov 2008 08:21:31 +0100</pubDate>
    <guid isPermaLink="false">http://www.ingo-schramm.de/blog/archives/4-guid.html</guid>
    
</item>
<item>
    <title>How to improve PHP performance in 30 minutes</title>
    <link>http://www.ingo-schramm.de/blog/archives/3-How-to-improve-PHP-performance-in-30-minutes.html</link>
            <category>PHP</category>
            <category>Scalability</category>
    
    <comments>http://www.ingo-schramm.de/blog/archives/3-How-to-improve-PHP-performance-in-30-minutes.html#comments</comments>
    <wfw:comment>http://www.ingo-schramm.de/blog/wfwcomment.php?cid=3</wfw:comment>

    <slash:comments>235</slash:comments>
    <wfw:commentRss>http://www.ingo-schramm.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=3</wfw:commentRss>
    

    <author>nospam@example.com (Ingo)</author>
    <content:encoded>
    You&#039;ve written a not so trivial PHP application and your web site is visited more and more frequently, 1 time per second, 10 times, 20 times per second, more. You transfered your database to a second mashine but still your webserver performance breaks down at 25 request per second. You install a byte code cache like the APC or XCache but your servers still do not deliver more than 30 or 40 requests. What now?&lt;br /&gt;
&lt;br /&gt;
You may spend some weeks to refactor your whole software. Or you invest 30 minutes to fix your file inclusions and you win some 100% performance - even more.&lt;br /&gt;
&lt;br /&gt;
The recipe is easy - watch your server process with strace, take care on file stats and try to reduce it to zero:&lt;br /&gt;
&lt;br /&gt;
- reduce your include_path to a single entry or don&#039;t use it at all&lt;br /&gt;
- include or require &lt;u&gt;absolute&lt;/u&gt; paths&lt;br /&gt;
- ensure that each try to include a file is a hit&lt;br /&gt;
- avoid file_exists(), is_file(), is_dir(), is_link() etc.&lt;br /&gt;
- avoid autoloading&lt;br /&gt;
&lt;br /&gt;
That&#039;s it.&lt;br /&gt;
&lt;br /&gt;
Each file system access forces the operating system to switch context and wastes a huge number of CPU cycles. If you have a long include path and the file to include is found at the end you have a lot of useless file stats. Even the byte code cache cannot protect you from this since it stores only files found, not files that do not exist. For each non existing file all the stats and lookups take place again and again. This is what your CPU works for, not your business logic.&lt;br /&gt;
&lt;br /&gt;
Stats are evil.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Mon, 17 Nov 2008 21:35:19 +0100</pubDate>
    <guid isPermaLink="false">http://www.ingo-schramm.de/blog/archives/3-guid.html</guid>
    
</item>

</channel>
</rss>