<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Increasing PHP performance</title>
	<atom:link href="http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/</link>
	<description>A tool for designers dealing with programmers dealing with designers...</description>
	<pubDate>Thu, 20 Nov 2008 21:15:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: kvz</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-653</link>
		<dc:creator>kvz</dc:creator>
		<pubDate>Sat, 06 Oct 2007 16:04:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-653</guid>
		<description>Another article about optimizing the performance of apache &#38; php for high traffic loads:
http://kevin.vanzonneveld.net/techblog/article/survive_heavy_traffic_with_your_webserver</description>
		<content:encoded><![CDATA[<p>Another article about optimizing the performance of apache &amp; php for high traffic loads:<br />
<a href="http://kevin.vanzonneveld.net/techblog/article/survive_heavy_traffic_with_your_webserver" rel="nofollow">http://kevin.vanzonneveld.net/techblog/article/survive_heavy_traffic_with_your_webserver</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph M</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-614</link>
		<dc:creator>Joseph M</dc:creator>
		<pubDate>Tue, 18 Sep 2007 15:51:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-614</guid>
		<description>I recently was having a performance problem iterating through a class in php 5 using $this to access a variable. 

I tried creating a reference to the variable ie
$var = &#38; $this-&#62;var;

The speed tests were impressive.  
At 1,000,000 iterations 
This()
Start Time:1188316233.75
End Time:1188316234.3781
Total Time:0.62805891036987

Ref()
Start Time:1188316234.3781
End Time:1188316234.5309
Total Time:0.15274381637573</description>
		<content:encoded><![CDATA[<p>I recently was having a performance problem iterating through a class in php 5 using $this to access a variable. </p>
<p>I tried creating a reference to the variable ie<br />
$var = &amp; $this-&gt;var;</p>
<p>The speed tests were impressive.<br />
At 1,000,000 iterations<br />
This()<br />
Start Time:1188316233.75<br />
End Time:1188316234.3781<br />
Total Time:0.62805891036987</p>
<p>Ref()<br />
Start Time:1188316234.3781<br />
End Time:1188316234.5309<br />
Total Time:0.15274381637573</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nickf</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-431</link>
		<dc:creator>nickf</dc:creator>
		<pubDate>Thu, 23 Aug 2007 14:56:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-431</guid>
		<description>I'm no expert on this, but here's my understanding:

Regarding == vs ===, the identity check (===) actually will be doing less processing because it doesn't have to cast variables to different types.

I did some benchmarking:

5,000,000 iterations
TESTS:
1.1: 1 == 1
1.2: 1 == '1'
1.3: 1 == 2
1.4: 1 == 'a'
2.1: 1 === 1
2.2: 1 === '1'
2.3: 1 === 2
2.4: 1 === 'a'

RESULTS:
1.1: 4.2496 (108.0435%)
1.2: 5.4232 (137.8819%)
1.3: 4.8647 (123.6827%)
1.4: 5.3762 (136.6878%)
2.1: 4.0064 (101.8609%)
2.2: 3.9332 (100%)
2.3: 3.9355 (100.059%)
2.4: 3.9373 (100.1045%)

so you can see that identity checking is much quicker.</description>
		<content:encoded><![CDATA[<p>I&#8217;m no expert on this, but here&#8217;s my understanding:</p>
<p>Regarding == vs ===, the identity check (===) actually will be doing less processing because it doesn&#8217;t have to cast variables to different types.</p>
<p>I did some benchmarking:</p>
<p>5,000,000 iterations<br />
TESTS:<br />
1.1: 1 == 1<br />
1.2: 1 == &#8216;1&#8242;<br />
1.3: 1 == 2<br />
1.4: 1 == &#8216;a&#8217;<br />
2.1: 1 === 1<br />
2.2: 1 === &#8216;1&#8242;<br />
2.3: 1 === 2<br />
2.4: 1 === &#8216;a&#8217;</p>
<p>RESULTS:<br />
1.1: 4.2496 (108.0435%)<br />
1.2: 5.4232 (137.8819%)<br />
1.3: 4.8647 (123.6827%)<br />
1.4: 5.3762 (136.6878%)<br />
2.1: 4.0064 (101.8609%)<br />
2.2: 3.9332 (100%)<br />
2.3: 3.9355 (100.059%)<br />
2.4: 3.9373 (100.1045%)</p>
<p>so you can see that identity checking is much quicker.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: molotov</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-267</link>
		<dc:creator>molotov</dc:creator>
		<pubDate>Sun, 29 Jul 2007 05:32:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-267</guid>
		<description>Uh, when copy/pasting the above, I forgot to remove the count() from the for loop, DUH.

I'm not posting on a Monday morning; I'm posting at 12:30 on a Saturday night and blame the goof on the fact that I'm looking up PHP optimizations on a Saturday night :P</description>
		<content:encoded><![CDATA[<p>Uh, when copy/pasting the above, I forgot to remove the count() from the for loop, DUH.</p>
<p>I&#8217;m not posting on a Monday morning; I&#8217;m posting at 12:30 on a Saturday night and blame the goof on the fact that I&#8217;m looking up PHP optimizations on a Saturday night <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: molotov</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-266</link>
		<dc:creator>molotov</dc:creator>
		<pubDate>Sun, 29 Jul 2007 05:31:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-266</guid>
		<description>@Mgccl:

for ($i=count($some_array);$i;){
--$i;
}

Is that the best way to this? Wouldn't it be better to use a temporary variable instead of asking the for loop to count the array each time? It was mentioned earlier in the comments, but not-seeing it here makes me wonder if it was intentional, or just intending to show the decrement.


$temp = count($some_array);
for ($i=count($temp);$i;){
--$i;
}</description>
		<content:encoded><![CDATA[<p>@Mgccl:</p>
<p>for ($i=count($some_array);$i;){<br />
&#8211;$i;<br />
}</p>
<p>Is that the best way to this? Wouldn&#8217;t it be better to use a temporary variable instead of asking the for loop to count the array each time? It was mentioned earlier in the comments, but not-seeing it here makes me wonder if it was intentional, or just intending to show the decrement.</p>
<p>$temp = count($some_array);<br />
for ($i=count($temp);$i;){<br />
&#8211;$i;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robin Mehner</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-231</link>
		<dc:creator>Robin Mehner</dc:creator>
		<pubDate>Fri, 20 Jul 2007 07:53:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-231</guid>
		<description>Oh, and one other thing:

Try Memcache for caching and xdebug for profiling, they both do their job very well.

(I'm sorry for the typos in my previous post ... switching between languages in the early morning ;-))</description>
		<content:encoded><![CDATA[<p>Oh, and one other thing:</p>
<p>Try Memcache for caching and xdebug for profiling, they both do their job very well.</p>
<p>(I&#8217;m sorry for the typos in my previous post &#8230; switching between languages in the early morning ;-))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robin Mehner</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-230</link>
		<dc:creator>Robin Mehner</dc:creator>
		<pubDate>Fri, 20 Jul 2007 07:50:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-230</guid>
		<description>Hi,

it's me again. Don't had the time for know to test the difference between "==" and "===" but for now I believe the benchmark (even if really GOOD benchmarks are seldom, because most of them missing important points)

@Logan:

Yes, that's clear. I think this post is intended to show everyone some small optimizations in the script language itselfs, nothing more.

It should be clear to everyone, that the real bottlenecks are elsewhere, so you can keep some simple rules:

1. use external resources wisely
2. do not code / use bloated code. Small code = fast code (in most cases ;))
3. include only the files that you really need
4. C code is faster than PHP code, so if you can solve the problem with an internal PHP function, do it!

and the most important rule:

5. Cache as much as possible!

alone the fifth point make way more sense than most of the code optimizations you can do ... and it keeps your code read able.

SQL optimization is a good point to. If you work with MySQL I recommend you the book: "High performance MySQL" from Jeremy D. Zawodny</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>it&#8217;s me again. Don&#8217;t had the time for know to test the difference between &#8220;==&#8221; and &#8220;===&#8221; but for now I believe the benchmark (even if really GOOD benchmarks are seldom, because most of them missing important points)</p>
<p>@Logan:</p>
<p>Yes, that&#8217;s clear. I think this post is intended to show everyone some small optimizations in the script language itselfs, nothing more.</p>
<p>It should be clear to everyone, that the real bottlenecks are elsewhere, so you can keep some simple rules:</p>
<p>1. use external resources wisely<br />
2. do not code / use bloated code. Small code = fast code (in most cases ;))<br />
3. include only the files that you really need<br />
4. C code is faster than PHP code, so if you can solve the problem with an internal PHP function, do it!</p>
<p>and the most important rule:</p>
<p>5. Cache as much as possible!</p>
<p>alone the fifth point make way more sense than most of the code optimizations you can do &#8230; and it keeps your code read able.</p>
<p>SQL optimization is a good point to. If you work with MySQL I recommend you the book: &#8220;High performance MySQL&#8221; from Jeremy D. Zawodny</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mgccl</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-228</link>
		<dc:creator>Mgccl</dc:creator>
		<pubDate>Wed, 18 Jul 2007 23:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-228</guid>
		<description>dancaragea, about that
&lt;pre lang="php"&gt;
for ($i=0;isset($some_array[$i]);++$i){	
}
&lt;/pre&gt;
I found it is not as fast as 
&lt;pre lang="php"&gt;
  $temp=count($some_array);
for ($i=0;$i
&lt;/pre&gt;
My test are from this code, on PHP5.2:
&lt;pre lang="php"&gt;
$some_array = range(0,100000);

    $timeparts = explode(' ',microtime());
  $starttime = $timeparts[1].substr($timeparts[0],1);
for ($i=0;isset($some_array[$i]);++$i){
	
	
}
  $timeparts = explode(' ',microtime());
  $endtime = $timeparts[1].substr($timeparts[0],1);
  echo bcsub($endtime,$starttime,6),'';
  
  $timeparts = explode(' ',microtime());
  $starttime = $timeparts[1].substr($timeparts[0],1);
  $temp=count($some_array);
for ($i=0;$i';
&lt;/pre&gt;
Also, in some cases, the array can be looped backwards. like this
&lt;pre lang="php"&gt;
for ($i=count($some_array);$i;){
--$i;
}
&lt;/pre&gt;
which is the fastest because compare to loop forward, one less conditional saved from every iteration.</description>
		<content:encoded><![CDATA[<p>dancaragea, about that</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color:#800080;">0</span>;isset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$some_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;++<span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I found it is not as fast as</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">  <span style="color: #000088;">$temp</span><span style="color: #339933;">=</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$some_array</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color:#800080;">0</span>;<span style="color: #000088;">$i</span></pre></div></div>

<p>My test are from this code, on PHP5.2:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$some_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100000</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #000088;">$timeparts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="">' '</span><span style="color: #339933;">,</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #000088;">$starttime</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$timeparts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeparts</span><span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color:#800080;">0</span>;isset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$some_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;++<span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$timeparts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="">' '</span><span style="color: #339933;">,</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #000088;">$endtime</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$timeparts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeparts</span><span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #990000;">echo</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$endtime</span><span style="color: #339933;">,</span><span style="color: #000088;">$starttime</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="">''</span>;
&nbsp;
  <span style="color: #000088;">$timeparts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="">' '</span><span style="color: #339933;">,</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #000088;">$starttime</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$timeparts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeparts</span><span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #000088;">$temp</span><span style="color: #339933;">=</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$some_array</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color:#800080;">0</span>;<span style="color: #000088;">$i</span><span style="">';</span></pre></div></div>

<p>Also, in some cases, the array can be looped backwards. like this</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$some_array</span><span style="color: #009900;">&#41;</span>;<span style="color: #000088;">$i</span>;<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #339933;">--</span><span style="color: #000088;">$i</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>which is the fastest because compare to loop forward, one less conditional saved from every iteration.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth Heyes</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-226</link>
		<dc:creator>Gareth Heyes</dc:creator>
		<pubDate>Wed, 18 Jul 2007 21:49:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-226</guid>
		<description>Yes obviously optimising your SQL statements would but this page was simply to point out ways to increase performance however slight.

If you would care to share some tips then please do. I might add SQL tips at a later stage.</description>
		<content:encoded><![CDATA[<p>Yes obviously optimising your SQL statements would but this page was simply to point out ways to increase performance however slight.</p>
<p>If you would care to share some tips then please do. I might add SQL tips at a later stage.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Logan Buesching</title>
		<link>http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-225</link>
		<dc:creator>Logan Buesching</dc:creator>
		<pubDate>Wed, 18 Jul 2007 18:49:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2007/07/13/increasing-php-performance/#comment-225</guid>
		<description>What are your thoughts on premature optimization?  IMO, most of these comments that have been posted *may* give you a few microseconds on each call, at most a few milliseconds.  I would assume that if you spent the same amount of time attempting to optimize your slowest SQL call, you will get orders of magnitude better returns than worrying about whether or not you are concatinating or using a comma in your echo statements.</description>
		<content:encoded><![CDATA[<p>What are your thoughts on premature optimization?  IMO, most of these comments that have been posted *may* give you a few microseconds on each call, at most a few milliseconds.  I would assume that if you spent the same amount of time attempting to optimize your slowest SQL call, you will get orders of magnitude better returns than worrying about whether or not you are concatinating or using a comma in your echo statements.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
