<?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>Che Hodgins &#187; inclued</title>
	<atom:link href="http://www.chehodgins.com/tag/inclued/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chehodgins.com</link>
	<description>Musings on Web Development</description>
	<lastBuildDate>Tue, 24 Nov 2009 02:39:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sorting out your PHP includes using Inclued</title>
		<link>http://www.chehodgins.com/php/sorting-out-your-php-includes-using-inclued/</link>
		<comments>http://www.chehodgins.com/php/sorting-out-your-php-includes-using-inclued/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 17:07:14 +0000</pubDate>
		<dc:creator>chehodgins</dc:creator>
				<category><![CDATA[pecl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[inclued]]></category>

		<guid isPermaLink="false">http://www.chehodgins.com/?p=188</guid>
		<description><![CDATA[This is the third edition of my weekly PECL package series. Check out my Scream article as well as my Sphinx article to learn about these extensions.
If you have ever inherited spaghetti code or worse, written spaghetti code, the following article is for you. This article is an introduction to the Inclued PECL extension. It [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This is the third edition of my weekly PECL package series. Check out my <a href="http://www.chehodgins.com/programming/php/weekly-pecl-package-scream/">Scream article</a> as well as my <a href="http://www.chehodgins.com/php/search-improvements-using-sphinx-mysql-and-pecl/">Sphinx article</a> to learn about these extensions.</strong></p>
<p>If you have ever inherited spaghetti code or worse, written spaghetti code, the following article is for you. This article is an introduction to the <a href="http://pecl.php.net/package/inclued">Inclued PECL extension</a>. It helps answer the common question &#8220;Where is this include coming from?&#8221;, something that I&#8217;ve asked myself before when working on some projects.</p>
<p>This extension works by <a href="http://t3.dotgnu.info/blog/php/inclued-gives-you-clue.html">overriding an opcode in Zend</a>, allowing it to log information regarding which files are being included, and from where. This information can be collected using a single function named inclued_get_data() or by setting inclued.dumpdir in php.ini to dump the data of each request.</p>
<p>The final step involves graphing this data to get a view of the include hierarchy. This can be done by converting the JSON encoded output into a <a href="http://en.wikipedia.org/wiki/DOT_language">dot</a> language file, and then converting it to an image or viewing it with an application such as <a href="http://www.graphviz.org/Gallery.php">Graphviz</a>.</p>
<p>To start, we need to install the inclued PECL extension:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mbpro:~ chehodgins$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> pecl <span style="color: #c20cb9; font-weight: bold;">install</span> inclued-alpha<br />
downloading inclued-0.1.0.tar ...<br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #c20cb9; font-weight: bold;">install</span> ok: channel:<span style="color: #000000; font-weight: bold;">//</span>pecl.php.net<span style="color: #000000; font-weight: bold;">/</span>inclued-0.1.0</div></td></tr></tbody></table></div>
<p>And add to php.ini and restart apache:</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">inclued.so</span><br />
inclued.enabled<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">1</span><br />
inclued.dumpdir<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/tmp</span></div></td></tr></tbody></table></div>
<p>Next, in our web browser we load the page that we wish to analyze. A file named inclued.*.* will be added to /tmp. We will convert to this to a dot file using the gengraph.php script that is included in the PECL package:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mbpro:tmp chehodgins$ php <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>gengraph.php <span style="color: #660033;">-i</span> inclued.00196.2<br />
Written inclued.out.dot...<br />
To generate images: dot <span style="color: #660033;">-Tpng</span> <span style="color: #660033;">-o</span> inclued.png inclued.out.dot</div></td></tr></tbody></table></div>
<p>Now we have the choice to either create a png using the dot command or simply opening with Graphviz.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mbpro:tmp chehodgins$ dot <span style="color: #660033;">-Tpng</span> <span style="color: #660033;">-o</span> ~<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>inclued.png inclued.out.dot</div></td></tr></tbody></table></div>
<p>And a super nice graph of the includes is generated as an image. Here is the graph of the includes in Wordpress (click to view fullscreen):</p>
<div id="attachment_191" class="wp-caption aligncenter" style="width: 1034px"><a href="http://www.chehodgins.com/wp-content/uploads/2009/04/inclued.png"><img class="size-large wp-image-191" title="inclued" src="http://www.chehodgins.com/wp-content/uploads/2009/04/inclued-1024x311.png" alt="Inclued run on Wordpress" width="1024" height="311" /></a><p class="wp-caption-text">Inclued run on Wordpress</p></div>
<p>Notice that there are a lot of includes, but in general there appears to be order. Now let&#8217;s check out osCommerce:</p>
<div id="attachment_194" class="wp-caption aligncenter" style="width: 1033px"><a href="http://www.chehodgins.com/wp-content/uploads/2009/04/inclued-osc.png"><img class="size-large wp-image-194" title="inclued-osc" src="http://www.chehodgins.com/wp-content/uploads/2009/04/inclued-osc-1023x723.png" alt="Inclued on osCommerce" width="1023" height="723" /></a><p class="wp-caption-text">Inclued on osCommerce</p></div>
<p>This also looks decent. What about magento?</p>
<div id="attachment_217" class="wp-caption aligncenter" style="width: 818px"><a href="http://www.chehodgins.com/wp-content/uploads/2009/04/inclued-magento-small.png"><img class="size-large wp-image-217" title="inclued-magento-small" src="http://www.chehodgins.com/wp-content/uploads/2009/04/inclued-magento-small-808x1024.png" alt="Inclued in Magento" width="808" height="1024" /></a><p class="wp-caption-text">Inclued in Magento</p></div>
<p>Holy crap, thats a lot of includes!</p>
<p>In conclusion, the inclued PECL extension can be useful in many situations, from trying to understand how and<br />
why a file is being included, to reorganizing your includes by seeing the dependencies. If anything, it can be an<br />
easy way to show off your application/framework&#8217;s include structure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chehodgins.com/php/sorting-out-your-php-includes-using-inclued/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
