<?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>Chris Abernethy . com&#187; PHP</title>
	<atom:link href="http://www.chrisabernethy.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisabernethy.com</link>
	<description></description>
	<lastBuildDate>Wed, 31 Mar 2010 14:42:26 +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>Profiling PHP with Xdebug and Webgrind</title>
		<link>http://www.chrisabernethy.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.chrisabernethy.com%2Fphp-profiling-xdebug-webgrind%2F&amp;seed_title=Profiling+PHP+with+Xdebug+and+Webgrind</link>
		<comments>http://www.chrisabernethy.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.chrisabernethy.com%2Fphp-profiling-xdebug-webgrind%2F&amp;seed_title=Profiling+PHP+with+Xdebug+and+Webgrind#comments</comments>
		<pubDate>Sat, 10 Jan 2009 20:24:40 +0000</pubDate>
		<dc:creator>Brownoxford</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://www.chrisabernethy.com/?p=178</guid>
		<description><![CDATA[Finding and fixing performance bottlenecks in PHP web applications can be both time-consuming and difficult. Fortunately, free tools like Xdebug and Webgrind allow you to easily find and visualize bottlenecks in your PHP scripts.]]></description>
			<content:encoded><![CDATA[Finding and fixing performance bottlenecks in PHP web applications can be both time-consuming and difficult. Fortunately, free tools like <a href="http://www.xdebug.org/index.php" rel="nofollow"  title="Xdebug Homepage">Xdebug</a> and <a href="http://code.google.com/p/webgrind/" rel="nofollow"  title="Webgrind Project Home">Webgrind</a> allow you to easily find and visualize bottlenecks in your PHP scripts.

<blockquote>Webgrind is an Xdebug profiling web frontend in PHP5. It implements a subset of the features of kcachegrind and installs in seconds and works on all platforms.<cite>--Webgrind</cite></blockquote>
<span id="more-178"></span>
<p>Anyone who has ever needed to profile code is probably familiar with <a href="http://kcachegrind.sourceforge.net/cgi-bin/show.cgi" rel="nofollow"  title="KcacheGrind">KcacheGrind</a> (a profile data visualization tool). KcacheGrind provides a way to visualize the profile data from a program execution, allowing you to quickly and easily see where the program is spending its time. Knowing where the execution bottlenecks are allows you to focus your optimization efforts in the correct places.</p>

<p>For a long time, the Xdebug extension for PHP has been able to (among other things) dump execution profile information to disk in a format that is usable by KcacheGrind, which is great if you are running Linux with KDE.</p>

<p>The webgrind project provides a web-based replacement for KcacheGrind that can be installed on any operating system, allowing you to visualize a portion of the Xdebug profiling data through a browser.</p>

<img src="http://www.chrisabernethy.com/wp-content/uploads/2009/01/webgrind_small.png" alt="Webgrind Interface" title="Webgrind Interface" width="440" height="324" class="aligncenter size-full wp-image-179" />

<h2>Installation</h2>
<p>Before using webgrind, you must first <a href="http://www.xdebug.org/docs/install" rel="nofollow"  title="Installing Xdebug">install Xdebug</a>.</p>
<p>Installing webgrind is pretty simple:</p>
<ol>
<li><a href="http://code.google.com/p/webgrind/downloads/list" rel="nofollow"  title="Download Webgrind">Download webgrind</a></li>
<li>Unzip webgrind in your web server's document root</li>
<li>Configure Xdebug and webgrind</li>
<li>Point your browser to where you installed webgrind</li>
</ol>

<h2>Configuration</h2>
<p>Unfortunately, webgrind does not often work "out-of-the-box"... There are a few configuration details that need to be dealt with in order to start profiling your code. The following PHP configuration directives can be used to control the behavior of Xcebug:</p>

<dl>
<dt>xdebug.profiler_enable</dt>
<dd>This directive actually turns on Xdebug's internal profiler. You <em>must</em> set this to <code>1</code> in order to have Xdebug actually produce output for webgrind to analyze.</dd>

<dt>xdebug.profiler_enable_trigger</dt>
<dd>
If you enable this option, profiles will only be generated if you pass a GET/POST parameter or cookie with the name <code>XDEBUG_PROFILE</code>, <em>e.g.</em>, <code>http://localhost/script.php?XDEBUG_PROFILE</code>. You must <em>not</em> enable <code>xdebug.profiler_enable</code> if you use this option.
</dd>

<dt>xdebug.profiler_output_dir</dt>
<dd>This directive tells Xdebug where to put the profile data. By default, it is set to '/tmp', which is usually fine. If you want, you can probably omit this from your Xdebug configuration.</dd>

<dt>xdebug.profiler_output_name</dt>
<dd>This value tells Xdebug how to create filenames for the data it writes to disk. By default, the value is set to <code>cachegrind.out.%p</code>, where <code>%p</code> will be replaced with the process ID. This is bad, and you will definitely need to change it. The problem is that Apache processes serve multiple requests, so each request in a given process will overwrite the profiling data from previous requests. Other <a href="http://www.xdebug.org/docs/all_settings#trace_output_name" rel="nofollow"  title="xdebug.profiler_output_name format specifiers">possible format specifiers</a> can be used.</dd>

<dt>xdebug.profiler_append</dt>
<dd>
Enabling this option will cause xdebug to append data to the output file if it already exists (the default behavior is to overwrite the output file). This is a handy option if you need to average out the profiling data over multiple script executions. In that case, be sure to set <code>xdebug.profiler_output_name</code> using a format that will ensure that each successive page load uses the same profiler output name, <em>e.g.</em>, <code>cachegrind.out.%s</code>.
</dd>
</dl>

<p>Assuming you have already loaded the Xdebug extension, the following additional PHP configuration directives should be a good starting point for you:</p>

<pre>
xdebug.profiler_enable = 1
xdebug.profiler_output_name = cachegrind.out.%t.%p
</pre>

<p>That's it, you should be ready to profile your PHP code with Xdebug and Cachegrind!</p>



	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.chrisabernethy.com%2Ffeeder%2F%3FFeederAction%3Dclicked%26amp%3Bfeed%3DArticles%2B%2528RSS2%2529%26amp%3Bseed%3Dhttp%253A%252F%252Fwww.chrisabernethy.com%252Fphp-profiling-xdebug-webgrind%252F%26amp%3Bseed_title%3DProfiling%2BPHP%2Bwith%2BXdebug%2Band%2BWebgrind&amp;title=Profiling%20PHP%20with%20Xdebug%20and%20Webgrind&amp;bodytext=Finding%20and%20fixing%20performance%20bottlenecks%20in%20PHP%20web%20applications%20can%20be%20both%20time-consuming%20and%20difficult.%20Fortunately%2C%20free%20tools%20like%20Xdebug%20and%20Webgrind%20allow%20you%20to%20easily%20find%20and%20visualize%20bottlenecks%20in%20your%20PHP%20scripts." title="Digg"><img src="http://www.chrisabernethy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.chrisabernethy.com%2Ffeeder%2F%3FFeederAction%3Dclicked%26amp%3Bfeed%3DArticles%2B%2528RSS2%2529%26amp%3Bseed%3Dhttp%253A%252F%252Fwww.chrisabernethy.com%252Fphp-profiling-xdebug-webgrind%252F%26amp%3Bseed_title%3DProfiling%2BPHP%2Bwith%2BXdebug%2Band%2BWebgrind&amp;title=Profiling%20PHP%20with%20Xdebug%20and%20Webgrind" title="StumbleUpon"><img src="http://www.chrisabernethy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.chrisabernethy.com%2Ffeeder%2F%3FFeederAction%3Dclicked%26amp%3Bfeed%3DArticles%2B%2528RSS2%2529%26amp%3Bseed%3Dhttp%253A%252F%252Fwww.chrisabernethy.com%252Fphp-profiling-xdebug-webgrind%252F%26amp%3Bseed_title%3DProfiling%2BPHP%2Bwith%2BXdebug%2Band%2BWebgrind" title="Sphinn"><img src="http://www.chrisabernethy.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.chrisabernethy.com%2Ffeeder%2F%3FFeederAction%3Dclicked%26amp%3Bfeed%3DArticles%2B%2528RSS2%2529%26amp%3Bseed%3Dhttp%253A%252F%252Fwww.chrisabernethy.com%252Fphp-profiling-xdebug-webgrind%252F%26amp%3Bseed_title%3DProfiling%2BPHP%2Bwith%2BXdebug%2Band%2BWebgrind&amp;title=Profiling%20PHP%20with%20Xdebug%20and%20Webgrind&amp;notes=Finding%20and%20fixing%20performance%20bottlenecks%20in%20PHP%20web%20applications%20can%20be%20both%20time-consuming%20and%20difficult.%20Fortunately%2C%20free%20tools%20like%20Xdebug%20and%20Webgrind%20allow%20you%20to%20easily%20find%20and%20visualize%20bottlenecks%20in%20your%20PHP%20scripts." title="del.icio.us"><img src="http://www.chrisabernethy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.chrisabernethy.com%2Ffeeder%2F%3FFeederAction%3Dclicked%26amp%3Bfeed%3DArticles%2B%2528RSS2%2529%26amp%3Bseed%3Dhttp%253A%252F%252Fwww.chrisabernethy.com%252Fphp-profiling-xdebug-webgrind%252F%26amp%3Bseed_title%3DProfiling%2BPHP%2Bwith%2BXdebug%2Band%2BWebgrind&amp;title=Profiling%20PHP%20with%20Xdebug%20and%20Webgrind&amp;source=Chris+Abernethy+.+com+&amp;summary=Finding%20and%20fixing%20performance%20bottlenecks%20in%20PHP%20web%20applications%20can%20be%20both%20time-consuming%20and%20difficult.%20Fortunately%2C%20free%20tools%20like%20Xdebug%20and%20Webgrind%20allow%20you%20to%20easily%20find%20and%20visualize%20bottlenecks%20in%20your%20PHP%20scripts." title="LinkedIn"><img src="http://www.chrisabernethy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.chrisabernethy.com%2Ffeeder%2F%3FFeederAction%3Dclicked%26amp%3Bfeed%3DArticles%2B%2528RSS2%2529%26amp%3Bseed%3Dhttp%253A%252F%252Fwww.chrisabernethy.com%252Fphp-profiling-xdebug-webgrind%252F%26amp%3Bseed_title%3DProfiling%2BPHP%2Bwith%2BXdebug%2Band%2BWebgrind&amp;t=Profiling%20PHP%20with%20Xdebug%20and%20Webgrind" title="Facebook"><img src="http://www.chrisabernethy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="" title="TwitThis"><img src="http://www.chrisabernethy.com/wp-content/plugins/sociable/images/" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.chrisabernethy.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.chrisabernethy.com%2Fphp-profiling-xdebug-webgrind%2F&amp;seed_title=Profiling+PHP+with+Xdebug+and+Webgrind/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
