<?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>More Than Scratch The Surface &#187; php</title>
	<atom:link href="http://www.scratch99.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scratch99.com</link>
	<description>A Journey In Web Development</description>
	<lastBuildDate>Mon, 30 Aug 2010 23:52:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Setting Cookies In WordPress &#8211; Trap For Beginners</title>
		<link>http://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/</link>
		<comments>http://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 21:18:29 +0000</pubDate>
		<dc:creator>Stephen Cronin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/</guid>
		<description><![CDATA[Copyright © 2010 Stephen Cronin. Visit the original article at http://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/.I recently wrote about displaying ads only to search visitors in WordPress. A key part of the technique described is to set a cookie, identifying the visitor as having come from a search engine. It should have been simple, but my PHP setcookie command didn’t [...]]]></description>
			<content:encoded><![CDATA[Copyright © 2010 <a href="http://www.scratch99.com">Stephen Cronin</a>. Visit the original article at <a href="http://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/">http://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/</a>.<br /><p>I recently wrote about <a href="http://www.scratch99.com/2008/09/avoid-smart-pricing-show-adsense-only-to-search-engine-visitors/">displaying ads only to search visitors</a> in WordPress. A key part of the technique described is to <strong>set a cookie</strong>, identifying the visitor as having come from a search engine. It should have been simple, but my <a href="http://php.net/setcookie">PHP setcookie command</a> didn’t appear to work. </p>
<p>I was using the setcookie command in the same way I’d done countless times before. I’d already taken into account that the cookie <strong>wouldn’t be available</strong> on the <strong>first page view</strong>. I couldn’t see anything wrong with the command I was using (in functions.php in the WordPress theme I was creating):</p>
<p class="codebox"><code>setcookie(&quot;sevisitor&quot;, 1, time()+3600);</code></p>
<p>This should have set a cookie with a name of sevisitor and a value of 1, that expires after one hour. However, <strong>no cookie was created</strong>.</p>
<p>After scouring the Internet in vain, I found a hint somewhere in the WordPress Support Forums (although I can’t find the page again now!). It suggested that the <strong>setcookie command&#8217;s domain parameter</strong> needed to be set.</p>
<p>I’d never used this parameter before and although I’ve seen explanations of what it does, I still can’t find a clear explanation of why you’d want to use it. Most descriptions of it mention that it’s optional, but don’t mention under what circumstances it would be necessary. Any <strong>PHP experts</strong> out there, please feel free to put me straight in the comments!</p>
<p>Anyway, after some experimentation, I got it working, by using the following command:</p>
<p class="codebox"><code>setcookie(&quot;sevisitor&quot;, 1, time()+3600, &quot;/&quot;, &quot;.scratch99.com&quot;); </code></p>
<p>Problem solved! As you can see I’ve done the following:</p>
<ul>
<li>added the path parameter, setting it to &#8220;/&#8221;, which allows the cookie within the entire domain. </li>
<li>added the domain parameter, setting it to my top level domain (.scratch99.com). Note the preceding . apparently makes it compatible with more browsers.</li>
</ul>
<p>Obviously, if you want to set a cookie in WordPress, you’ll have to <strong>replace .scratch99.com with the domain you are using</strong>.</p>
<p>Alternatively, you could let WordPress work out the domain for you, by using the following:</p>
<p class="codebox"><code>setcookie(&quot;sevisitor&quot;, 1, time()+3600, &quot;/&quot;, str_replace(&#039;http://www&#039;,&#039;&#039;,get_bloginfo(&#039;url&#039;)) );</code></p>
<p>This uses the <code>get_bloginfo(&#039;url&#039;))</code> command to get the site’s URL from WordPress, then strips the preceding <code>http://www</code> from it, leaving only the domain. Note, if you don’t use the www on your site, you’ll need to change: </p>
<p class="codebox"><code>str_replace(&#039;http://www&#039;</code></p>
<p>to </p>
<p class="codebox"><code>str_replace(&#039;http://&#039;</code></p>
<p>However, it’s really not worth doing things this way – your site will be <em>slightly</em> faster if you hard code your domain in. </p>
<p>The only time you’d want to use the above would be if you were putting this into a <strong>WordPress Theme</strong> that you were creating to be distributed. In that case, you’d probably want to make it a little cleverer, so that it works whether or not the www is present. But I’ll leave that to you to work out!</p>
<p>Anyway, the lesson I learned: <strong>If you want to set a cookie in WordPress, you must set the path and domain parameters</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>NetBeans IDE 6.5 Beta for PHP Developers</title>
		<link>http://www.scratch99.com/2008/08/netbeans-ide-65-beta-for-php-developers/</link>
		<comments>http://www.scratch99.com/2008/08/netbeans-ide-65-beta-for-php-developers/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 07:31:11 +0000</pubDate>
		<dc:creator>Stephen Cronin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.scratch99.com/2008/08/netbeans-ide-65-beta-for-php-developers/</guid>
		<description><![CDATA[Copyright © 2010 Stephen Cronin. Visit the original article at http://www.scratch99.com/2008/08/netbeans-ide-65-beta-for-php-developers/.In one of my older posts, on PHP Performance Profiling with APD, there’s a discussion in the comments about which IDE is best to use with PHP. Terence Chang recommends Zend Studio and mentions Eclipse. Dreamweaver&#8217;s also discussed and I state that I just use [...]]]></description>
			<content:encoded><![CDATA[Copyright © 2010 <a href="http://www.scratch99.com">Stephen Cronin</a>. Visit the original article at <a href="http://www.scratch99.com/2008/08/netbeans-ide-65-beta-for-php-developers/">http://www.scratch99.com/2008/08/netbeans-ide-65-beta-for-php-developers/</a>.<br /><p>In one of my older posts, on <a href="http://www.scratch99.com/2007/12/php-performance-profiling-with-apd-on-windows/"><strong>PHP Performance Profiling with APD</strong></a>, there’s a discussion in the comments about which IDE is best to use with PHP. <a href="http://www.terencechang.com/">Terence Chang</a> recommends Zend Studio and mentions Eclipse. Dreamweaver&#8217;s also discussed and I state that I just use a text editor (with syntax highlighting).</p>
<p>Against that backdrop, I read with interest that the <strong>NetBeans IDE 6.5 Beta</strong> has <a href="http://download.netbeans.org/netbeans/6.5/beta/"><strong>just been released</strong></a> and that <a href="http://netbeans.dzone.com/articles/netbeans-ide-65-beta-offers-bu"><strong>it now caters to PHP developers</strong></a> (article by Lloyd Dunn).</p>
<h2>NetBeans IDE 6.5 for PHP</h2>
<p>Lloyd’s article discusses the features present in NetBeans IDE 6.5 Beta for PHP developers. To quote Lloyd:</p>
<blockquote><p>As web developers increasingly tackle large-scale projects that use PHP together with MySQL, they stand to benefit from an IDE that can efficiently manage their growing code base. Fortunately, the newly released NetBeans IDE 6.5 Beta arrives tailor-made to help PHP developers with their particular coding requirements. </p></blockquote>
<p>He goes on to list the features that are included:</p>
<blockquote><p>code completion, syntax highlighting, marking of occurrences, refactoring, code templates, pop-up documentation, easy code navigation, editor warnings, a task list, as well as a debugger.</p></blockquote>
<p>Lloyd looks in detail at the <strong>Debugger</strong> and the <strong>integration with MySQL</strong> as well as mentioning that the PHP only distribution is only 20MB (amazing!).</p>
<p>It sounds great to me! I haven’t had time to try it yet and I don’t really need a <strong>full blown IDE</strong> for the PHP coding I’m doing at present, but I’ve downloaded it and will give it a spin sometime soon.</p>
<p>If you’re interested, I’d urge you to read <a href="http://netbeans.dzone.com/articles/netbeans-ide-65-beta-offers-bu">Lloyd’s article</a> in full.</p>
<h2>A Quick Look At The PHP IDE Competition</h2>
<p>Although <strong>Dreamweaver</strong> is great for most web development, it’s really not up to scratch when it comes to PHP development and it costs money. </p>
<p><strong>Zend Studio</strong> has an <strong>excellent reputation, but it&#8217;s expensive</strong>. That might be an option if you are a full time PHP developer, but if won’t be appealing to the part timers out there, such as myself.</p>
<p>As I’ve said, I use a text editor (with syntax highlighting) for most of my coding, but I’m only working on short simple projects at present. For more complex projects, a comprehensive IDE would be necessary.</p>
<p>So that leaves <strong>Eclipse PHP</strong> (PDT) and now <strong>NetBeans IDE</strong> as the <strong>free options</strong>. Which is best? I haven’t tried them yet, but NetBeans is a lot smaller to download (if you choose PHP only), has the debugger built in (you have install a separate debugger for Eclipse). It seems to have a lot going for it. </p>
<p><strong>I’d recommend trying them both</strong>, but there’s no doubt that NetBeans is one to seriously consider. </p>
<h2>Final Thoughts</h2>
<p><strong>What do you use for your PHP coding</strong>? Do you have experience with NetBeans, or any of the other IDEs mentioned? If so, let me know in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scratch99.com/2008/08/netbeans-ide-65-beta-for-php-developers/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Creating A JavaScript Array Dynamically Via PHP</title>
		<link>http://www.scratch99.com/2008/03/creating-javascript-array-dynamically-from-php-array/</link>
		<comments>http://www.scratch99.com/2008/03/creating-javascript-array-dynamically-from-php-array/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 03:19:55 +0000</pubDate>
		<dc:creator>Stephen Cronin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.scratch99.com/2008/03/creating-javascript-array-dynamically-from-php-array/</guid>
		<description><![CDATA[Copyright © 2010 Stephen Cronin. Visit the original article at http://www.scratch99.com/2008/03/creating-javascript-array-dynamically-from-php-array/.If you use PHP to create web pages, there may be times when you need to create a JavaScript array dynamically from a PHP array. This is not hard to do, but there is a trap you need to be careful of: dealing with arrays [...]]]></description>
			<content:encoded><![CDATA[Copyright © 2010 <a href="http://www.scratch99.com">Stephen Cronin</a>. Visit the original article at <a href="http://www.scratch99.com/2008/03/creating-javascript-array-dynamically-from-php-array/">http://www.scratch99.com/2008/03/creating-javascript-array-dynamically-from-php-array/</a>.<br /><p>If you use PHP to create web pages, there may be times when you need to <strong>create a JavaScript array dynamically from a PHP array</strong>. This is not hard to do, but there is a trap you need to be careful of: dealing with <strong>arrays containing only a single element</strong>.</p>
<div class="csstextbox1">This post is for the PHP coders out there. If you don&#8217;t write code, it may not be for you.</div>
<h2>My Original Solution</h2>
<p>When writing the <a title="The LocalCurrency plugin for WordPress detects the visitor&#39;s country (by IP address) and shows them currency values in their local currency (with exchange rates from Yahoo! Finance)" href="http://www.jobsinchina.com/resources/wordpress-plugin-localcurrency/" target="_blank"><strong>LocalCurrency</strong></a> WordPress plugin, I had a PHP array containing values that needed to be converted. The plugin uses <strong>AJAX techniques</strong> to do the conversions after the page has loaded, so it doesn&#8217;t slow down page load times waiting for Yahoo! Finance. The JavaScript to do this needed to access the information in the PHP array.</p>
<p>I decided the best way to implement this was to <strong>create a JavaScript array from the PHP array</strong>. I came up with the following code: </p>
<pre class="brush: php;">
// create script string to append to content. First create the value array in JavaScript.
$script = $script . &quot;\n&quot; . '&lt;script type=&quot;text/javascript&quot;&gt; '. &quot;\nvar lcValues = new Array(&quot;;
foreach ($lc_values as $key =&gt; $value){
	if ($key &lt; (count($lc_values)-1)){
		$script = $script . $value . ',';
	}
	else {
		$script = $script . $value . &quot;);\n&quot;;
	}
}
</pre>
<div class="csstextbox1">Note: I&#8217;m not echoing the script directly. I&#8217;m appending it to a string variable, which itself will be appended to the end of the post content.</div>
<p>This code will create a JavaScript array and populate it with values from a PHP array called $lc_values, which has been created elsewhere. If $lc_values contains the values 25, 34 and 16 (with keys 0, 1 and 2 respectively), then the above code will create the following JavaScript:</p>
<pre class="brush: jscript;">var lcValues = new Array(25,34,16);</pre>
<p>Great! This is just what I want. A JavaScript array containing the 3 values will be created,  and I can use it to convert the values via JavaScript.</p>
<h2>The Problem &#8211; Arrays With A Single Element</h2>
<p>The problem occurs when there is <strong>only one value to convert</strong>. For example, if $lc_values only contains 25, this will create:</p>
<pre class="brush: jscript;">var lcValues = new Array(25);</pre>
<p>JavaScript will see this as an instruction to create <em>an array with 25 elements</em>, rather than <em>an array with one element with a value of 25</em>. Later, when you try to access lcValues[0], it will be undefined and will return <strong>NaN</strong> (Not a Number) when you try to use it.</p>
<p><em>You cannot use new Array() to create an array with a single numeric element.</em></p>
<h2>The Solution</h2>
<p>I got around this problem by checking the number of elements in the PHP array, using the count function. If there is <strong>more than one element</strong>, it will create the same JavaScript as the original code did. If there is only a <strong>single element</strong> (for example, 25), it will create the follow JavaScript:</p>
<pre class="brush: jscript;">
var lcValues = new Array(1);
lcValues[0]=25;
</pre>
<p>The final code I used looks like this:</p>
<pre class="brush: php;">
// create script string to append to content. First create the value array in JavaScript.
$script = $script . &quot;\n&quot; . '&lt;script type=&quot;text/javascript&quot;&gt; '. &quot;\nvar lcValues = new Array(&quot;;
if (count($lc_values)&gt;1) {
	foreach ($lc_values as $key =&gt; $value){
		if ($key &lt; (count($lc_values)-1)){
			$script = $script . $value . ',';
		}
		else {
			$script = $script . $value . &quot;);\n&quot;;
		}
	}
}
else {	// can't create an array that just has one integer element using Array()
	$script = $script . &quot;1);\nlcValues[0]=&quot; . $lc_values[0] . &quot;;\n&quot;;
}
</pre>
<div class="csstextbox1">Note: I can safely use <strong>else</strong>, because of code outside the above snippet, ensuring the PHP array will have at least one element at this point. You may need to be careful about this. If it&#8217;s possible that your PHP array may be empty, consider using <strong>elseif (count($phparrayname)==1)</strong> instead.</div>
<h2>Final Thoughts</h2>
<p>There are obviously different ways to do this, but this is what works for me. If it helps anyone else, great! If anyone knows a better way to do this, let me know in the comments.</p>
<script type="text/javascript">Nifty("div.csstextbox1","bgcolor-#FFFFFF");</script>]]></content:encoded>
			<wfw:commentRss>http://www.scratch99.com/2008/03/creating-javascript-array-dynamically-from-php-array/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>PHP Performance Profiling With APD On Windows</title>
		<link>http://www.scratch99.com/2007/12/php-performance-profiling-with-apd-on-windows/</link>
		<comments>http://www.scratch99.com/2007/12/php-performance-profiling-with-apd-on-windows/#comments</comments>
		<pubDate>Thu, 27 Dec 2007 08:29:22 +0000</pubDate>
		<dc:creator>Stephen Cronin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>

		<guid isPermaLink="false">http://www.scratch99.com/2007/12/php-performance-profiling-with-apd-on-windows/</guid>
		<description><![CDATA[Copyright © 2010 Stephen Cronin. Visit the original article at http://www.scratch99.com/2007/12/php-performance-profiling-with-apd-on-windows/.When writing code, its important to keep system performance in mind. No matter how useful your software is, if it places too much stress on the server, it won&#8217;t be used. How can you tell if your code is efficient? Well, experience helps, but it [...]]]></description>
			<content:encoded><![CDATA[Copyright © 2010 <a href="http://www.scratch99.com">Stephen Cronin</a>. Visit the original article at <a href="http://www.scratch99.com/2007/12/php-performance-profiling-with-apd-on-windows/">http://www.scratch99.com/2007/12/php-performance-profiling-with-apd-on-windows/</a>.<br /><p>When writing code, its important to keep system performance in mind. No matter how useful your software is, if it places too much stress on the server, it won&#8217;t be used. How can you tell if your code is efficient? Well, experience helps, but it also pays to have good tools.</p>
<p>Most of the code I write is fairly simple and should only place minimal load on the server, but I wanted to make sure that its as efficient as possible. I went looking for a <strong>PHP performance profiling tool</strong> to help me.</p>
<p>My search led me to Jonathan Oxer&#8217;s <strong><a title="Excellent article on using APD to create a performance profile for PHP scripts" href="http://www.linuxjournal.com/article/7213" target="_blank">PHP Performance Profiling</a></strong> article. This mentions several tools, but focuses on <strong><a title="Home page of the Advanced PHP Debugger (APD)" href="http://pecl.php.net/package/apd" target="_blank">Advanced PHP Debugger</a></strong> (APD). This looked good, so <em>I tried</em> to give it go. I eventually got it working, but it wasn&#8217;t easy &#8211; the problem was that I wanted to run it on Windows XP.</p>
<div class="csstextbox1">The focus of this post is how to get <strong>APD running on Windows</strong>. If you don&#8217;t write PHP code or use Windows, then this article is probably not for you!</div>
<h2>What Is Performance Profiling?</h2>
<p>Before I get into it, I&#8217;m aware that some of you will be asking &#8220;<em>What&#8217;s performance profiling</em>?&#8221; Here&#8217;s Jonathon&#8217;s description, which says it perfectly:</p>
<blockquote>
<p>Performance profiling runs your code in a controlled environment and returns a report listing such statistics as time spent within each function, how long each database query takes and how much memory has been used. </p>
<p>By doing performance profiling on your code, you quickly can see where you may be wasting time with slow database queries or inefficient code. Having this information then allows you to spend your time tuning PHP and SQL where it needs it most. No more guessing what&#8217;s going on internally: performance profiling gives you hard figures.</p>
</blockquote>
<p>APD is a tool which helps you to do this.</p>
<h2>The Problem With Installing APD on Windows</h2>
<p>To run APD in the Windows environment, you need the <strong>php_apd.dll </strong>file. Unfortunately, the installation package (from the <strong><a title="Home page of the Advanced PHP Debugger" href="http://pecl.php.net/package/apd" target="_blank">APD site</a></strong>) doesn&#8217;t include this file. The readme notes indicate that you need to compile APD yourself.</p>
<p>Well, I don&#8217;t have a C++ compiler installed and I wasn&#8217;t interested in downloading one and messing around with setting it up to compile PHP. That would take more time than I was willing to spend.</p>
<p>Surely the compiled file must be available somewhere on the Internet? Well, yes, but information on where to get it is buried amongst an avalanche of pages with no information (people asking &#8220;<em>where do I get</em>&#8220;, but no answer) or pages with misleading advice, leading to dlls that don&#8217;t work.</p>
<h2>So Where DO I Get The Php_apd.dll File?</h2>
<p>The <strong>php_apd.dll</strong> file is contained in the PECL extension file.</p>
<p>If you&#8217;re using the latest version of PHP, go to the <strong>Windows Binaries</strong> section of the <a title="The download page on php.net" href="http://www.php.net/downloads.php" target="_blank"><strong>PHP Downloads</strong></a> page and download the <strong>PECL 5.x.x Win32 binaries </strong>file (where 5.x.x is the latest version). The php_apd.dll file is in this zip file.</p>
<p>If you&#8217;re using an older version of PHP5, go to the <a title="The Unsupported Historical Releases available from the php.net website" href="http://www.php.net/releases/index.php" target="_blank"><strong>Unsupported Historical Releases</strong></a> page, locate the version of PHP you are using and download <strong>Collection of PECL modules for PHP 5.x.x</strong> file (where 5.x.x is the version you&#8217;re using). The php_apd.dll file is in this zip file.</p>
<p>If you&#8217;re using PHP4, I&#8217;m afraid I can&#8217;t tell you where to find the file. There is no separate PECL download for PHP4 versions, because <em>most </em>PECL modules were included with PHP4 (rather than in a separate file as with PHP5). Unfortunately, it seems the APD extension wasn&#8217;t one of those included.</p>
<h2>Setting APD Up</h2>
<p>Once you&#8217;ve got the <strong>php_apd.dll</strong> file, here&#8217;s how to set APD up:</p>
<p>First, make sure you have the <strong>PEAR extension</strong> installed, as APD uses its <strong>Console\Getopt.php</strong> script. If it is installed, there will be files and folders in the <strong>C:\php\pear</strong> folder (assuming PHP is installed in <strong>C:\php</strong>). If the folder is empty (there may be one file) or doesn&#8217;t exist, you need to install PEAR.</p>
<p>Installing PEAR should be as simple as running <strong>go-pear.bat </strong>in the <strong>C:\php </strong>folder. This asks a few questions, connects to the PEAR site and downloads the appropriate files. If PEAR support is not included in your version of PHP, you will have to download it from the <strong><a title="The home page for the PEAR extension for PHP" href="http://pear.php.net/" target="_blank">PEAR website</a></strong> and install it yourself.</p>
<p>Second, copy the <strong>php_apd.dll</strong> file to the <strong>C:\php\ext</strong> folder &#8211; assuming this is where your extensions live. If you are unsure where they live, locate your <strong>php.ini</strong> file and check the <strong>extension_dir</strong> setting. This is the folder you need to copy php_apd.dll to.</p>
<p>Third, edit <strong>php.ini</strong> and add the following to the Dynamic extensions section:</p>
<p class="codebox"><code>extension=php_apd.dll</code></p>
<p>I&#8217;ve seen it reported that you need to add:</p>
<p class="codebox"><code>zend_extension = c:\php\php_apd.dll<br />
apd.dumpdir = .<br />
apd.statement_trace = 1 </code></p>
<p>but I didn&#8217;t need to, probably because I&#8217;m not using the Zend extension.</p>
<p>To check if <strong>APD</strong> is loaded, run the phpinfo() command. If you&#8217;re not sure how to do this, read the following tutorial on <strong><a title="A tutorial on creating a simple page that displays phpinfo()" href="http://www.htmlgoodies.com/beyond/php/article.php/3472431" target="_blank">creating a page that displays phpinfo()</a></strong>. If you find an <strong>APD</strong> section somewhere on the page, it&#8217;s loaded.</p>
<h2>Using APD</h2>
<p>For more information on using APD, see <strong><a title="The article on using APD by Jonathon Oxer" href="http://www.linuxjournal.com/article/7213" target="_blank">Jonathon&#8217;s article</a></strong>, but here&#8217;s what I did:</p>
<p>1. I added the following to the top of the script I wanted to profile:</p>
<div style="margin: 9px 0px 0px 30px;text-align:left;font-size:.9em;border:#ddd 1px solid;width:320px;padding:5px;">apd_set_pprof_trace(&#39;C:\temp&#39;);</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;where C:\Temp is the path I want the output file to be created in.</p>
<p>2. I ran the script once to create the output file.</p>
<p>3. I opened the command prompt, changed to the directory with the <br />&nbsp;&nbsp;&nbsp;&nbsp;output file and typed the following:</p>
<div style="margin: 9px 0px 0px 30px;text-align:left;font-size:.9em;border:#ddd 1px solid;width:320px;padding:5px;">c:\php\php.exe pprofp -u &lt;filename&gt; &gt;output.txt</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;(you need to replace &lt;filename&gt; with the name of the output file).</p>
<div class="csstextbox1">If you get an error saying there is no pprofp file, try <a href="http://www.scratch99.com/wp-content/uploads/2008/01/pprofp">downloading</a> a copy of mine and put it into the folder containing the output file. Note: It should have no extension.</div>
<p>There you go &#8211; PHP performance profiling&#8230; The information is in output.txt.</p>
<h2>APD Not For Profiling WordPress Plugins</h2>
<p>I was hoping to use APD to profile my <a title="My WordPress plugins page" href="http://www.scratch99.com/wordpress-plugins-by-stephen-cronin/" target="_blank"><strong>WordPress plugins</strong></a>. Unfortunately, its not suitable for this, because plugins hook into the WordPress core &#8211; so APD picks up everything else that&#8217;s going on as well. In hindsight, I should have realised this before I tried!</p>
<p>APD could be used to profile the performance of WordPress as a whole. People are becoming more aware of <a title="Post on Perishable Press highlighting performace issues with WordPress" href="http://perishablepress.com/press/2007/12/10/more-server-mayhem/" target="_blank"><strong>WordPress performance</strong></a> and are tweaking it to improve performance. Using APD while making changes could provide valuable insight into the effectiveness of the changes.</p>
<div class="csstextbox1">It&#8217;s also worth mentioning Lucia&#8217;s <a title="A plugin to help detect which plugins are taking up too much CPU" href="http://money.bigbucksblogger.com/pluginhogdetector-plugin-helps-you-find-cpu-hogging-plugins/" target="_blank"><strong>PluginHogDetector plugin</strong></a> for WordPress. This works by reporting how long it takes to process various parts of the page. To test a plugin (or change), simply compare the times before and after the plugin is activated (or the change is made). This isn&#8217;t as exact as performance profiling, lacking a breakdown of functions, how many times they&#8217;re called, how much memory they use, etc, but its simple and useful.</div>
<h2>The Final Word</h2>
<p>Evaluating the performance of your code is very important. I have a few projects on the go where APD will help me do that, so it was worth the struggle to get it working.</p>
<p>If you have any other tips for <strong>measuring PHP performance</strong> let me know!</p>
<script type="text/javascript">Nifty("div.csstextbox1","bgcolor-#FFFFFF");</script>]]></content:encoded>
			<wfw:commentRss>http://www.scratch99.com/2007/12/php-performance-profiling-with-apd-on-windows/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (enhanced)
Database Caching using disk
Object Caching 615/646 objects using disk

Served from: www.scratch99.com @ 2010-09-10 19:34:24 -->