<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Software Developing &#187; Performance</title>
	<atom:link href="http://www.phpdeveloping.co.za/category/performance/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpdeveloping.co.za</link>
	<description>for the love of PHP Development</description>
	<lastBuildDate>Tue, 29 Sep 2009 15:38:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How long does your script run?</title>
		<link>http://www.phpdeveloping.co.za/performance/how-long-does-your-script-run.html</link>
		<comments>http://www.phpdeveloping.co.za/performance/how-long-does-your-script-run.html#comments</comments>
		<pubDate>Wed, 12 Aug 2009 19:51:48 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[load speed]]></category>
		<category><![CDATA[running time]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=127</guid>
		<description><![CDATA[A while back I launched WebSpeedTest.co.za which is just a little script to check how long it takes to load your website.  It doesn&#8217;t take into account loading of all objects on the website, just the HTML.
Some of the code can be used in your PHP script to see how long it takes to [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I launched <a href="http://www.webspeedtest.co.za/">WebSpeedTest.co.za</a> which is just a little script to check how long it takes to load your website.  It doesn&#8217;t take into account loading of all objects on the website, just the HTML.</p>
<p>Some of the code can be used in your PHP script to see how long it takes to load.</p>
<p>First what you do is add this at the very top of your script.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$time</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: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time</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: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span></pre></div></div>

<p>That will have recorded your start time in the variable $start.</p>
<p>Now, at the very end of your script add this in:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$time</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: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time</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: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$finish</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$total_time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$finish</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>$total_time now contains the amount of seconds it took to run your script.  This can be useful for debugging to check where you might have bottlenecks.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/performance/how-long-does-your-script-run.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ternary Operators</title>
		<link>http://www.phpdeveloping.co.za/performance/ternary-operators.html</link>
		<comments>http://www.phpdeveloping.co.za/performance/ternary-operators.html#comments</comments>
		<pubDate>Wed, 22 Jul 2009 15:36:49 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[ternary operators]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=3</guid>
		<description><![CDATA[Instead of the normal if-else statements that most of us are use to, why not start using ternary operators.
Normal if-else statement:

if &#40;empty&#40;$v&#41;&#41; &#123;
$action = 'default';
&#125; else &#123;
$action = $v;
&#125;

Replacing the above 5 lines of code with just one line of code:

$action = &#40;empty&#40;$v&#41;&#41; ? 'default' : $v;

This might not increase the actual performance of the [...]]]></description>
			<content:encoded><![CDATA[<p>Instead of the normal if-else statements that most of us are use to, why not start using ternary operators.</p>
<p>Normal if-else statement:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Replacing the above 5 lines of code with just one line of code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'default'</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span></pre></div></div>

<p>This might not increase the actual performance of the execution, but it does use fewer lines to code the same thing as well as making it easier to read.  Make sure not to use more than one ternary operator in a single statement, as PHP doesn’t always know what to do in those situations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/performance/ternary-operators.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
