<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PHP: The include() include_once() performance debate</title>
	<atom:link href="http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/</link>
	<description>Web Programming &#038; IT Consultancy</description>
	<lastBuildDate>Fri, 16 Dec 2011 09:38:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: PHP: Include vs Require &#124; Sevenpixels</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1627</link>
		<dc:creator>PHP: Include vs Require &#124; Sevenpixels</dc:creator>
		<pubDate>Fri, 25 Mar 2011 21:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1627</guid>
		<description>[...] wise it looks like using either of the _once functions is faster. Include beats out require. So if you are looking to squeeze out every little bit of performance [...]</description>
		<content:encoded><![CDATA[<p>[...] wise it looks like using either of the _once functions is faster. Include beats out require. So if you are looking to squeeze out every little bit of performance [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PHP: Include vs Require&#160;&#124;&#160;Sevenpixels Web Design</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1615</link>
		<dc:creator>PHP: Include vs Require&#160;&#124;&#160;Sevenpixels Web Design</dc:creator>
		<pubDate>Tue, 09 Nov 2010 17:25:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1615</guid>
		<description>[...] wise it looks like using either of the _once functions is faster. Include beats out require. So if you are looking to squeeze out every little bit of performance [...]</description>
		<content:encoded><![CDATA[<p>[...] wise it looks like using either of the _once functions is faster. Include beats out require. So if you are looking to squeeze out every little bit of performance [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Artur Ejsmont</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1598</link>
		<dc:creator>Artur Ejsmont</dc:creator>
		<pubDate>Mon, 18 Oct 2010 19:01:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1598</guid>
		<description>nice post!

from my experience with tight optimization, autoload is not always fastest either. if you include some files for all requests (or 98% of them) its faster to do it with a bunch of req ince with abs path.

also difference between abs and rel increases when you have more dirs on the include path .. that is tricky as depends on env so better check prod setup ;) ... could be worth checking the numbers :)

cheers</description>
		<content:encoded><![CDATA[<p>nice post!</p>
<p>from my experience with tight optimization, autoload is not always fastest either. if you include some files for all requests (or 98% of them) its faster to do it with a bunch of req ince with abs path.</p>
<p>also difference between abs and rel increases when you have more dirs on the include path .. that is tricky as depends on env so better check prod setup <img src='http://blog.seeit.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  &#8230; could be worth checking the numbers <img src='http://blog.seeit.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francis</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1144</link>
		<dc:creator>Francis</dc:creator>
		<pubDate>Wed, 16 Jun 2010 17:52:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1144</guid>
		<description>@Hal / @Greg:

In fairness the intention was to see how quick an include_once()/require_once() is compared to an include()/require() statement when the statement is including the same file more than once - perhaps I should have been more clear about that at the outset. I wouldn&#039;t assume that a single include_once()/require_once() statement is quicker than a single include()/require() statement.

But fair enough - I&#039;ve taken the bait and tweaked the tests - &lt;a href=&quot;#round2&quot; rel=&quot;nofollow&quot;&gt;results are above&lt;/a&gt;. This time each file was only included/required twice and Apache Bench was used to invoke the actual scripts.

@Greg:

Why does this matter? Well, I&#039;d rather know than guess and the debate has been around for years. My conclusions are of course subjective, and (fancy charts notwithstanding) the empirical evidence is that include_once() and require_once() are the quickest - not the slowest.

My conclusions (the use of relative paths and that require_once()/include_once)() are quicker) are my own and I would hardly call them recommendations.

@Everyone:

What about some code to contradict/confirm these findings?</description>
		<content:encoded><![CDATA[<p>@Hal / @Greg:</p>
<p>In fairness the intention was to see how quick an include_once()/require_once() is compared to an include()/require() statement when the statement is including the same file more than once &#8211; perhaps I should have been more clear about that at the outset. I wouldn&#8217;t assume that a single include_once()/require_once() statement is quicker than a single include()/require() statement.</p>
<p>But fair enough &#8211; I&#8217;ve taken the bait and tweaked the tests &#8211; <a href="#round2" rel="nofollow">results are above</a>. This time each file was only included/required twice and Apache Bench was used to invoke the actual scripts.</p>
<p>@Greg:</p>
<p>Why does this matter? Well, I&#8217;d rather know than guess and the debate has been around for years. My conclusions are of course subjective, and (fancy charts notwithstanding) the empirical evidence is that include_once() and require_once() are the quickest &#8211; not the slowest.</p>
<p>My conclusions (the use of relative paths and that require_once()/include_once)() are quicker) are my own and I would hardly call them recommendations.</p>
<p>@Everyone:</p>
<p>What about some code to contradict/confirm these findings?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Beaver</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1136</link>
		<dc:creator>Greg Beaver</dc:creator>
		<pubDate>Wed, 16 Jun 2010 04:31:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1136</guid>
		<description>1) If you read the benchmark carefully, you can see that in fact what you want to compare is not the apache server, but the *difference* between the speeds of PHP using the same apache setup.  Note that in each case, a single request is made to the apache server.  In other words, because all of the tests use the same apache setup, and the apache server is polled more than 10,000 times over the course of a minute, the measured difference can be reliably attributed to differences in PHP execution speed, and not in any quirks of apache.
2) include/require are not functions, and if you are executing the same code over and over and over again with a single file, it will hit the realpath cache, and some other optimizations.  You benchmark is not just synthetic, it has absolutely nothing to do with real-world performance of include/require.

Why does this even matter?  You make some assertions with fancy charts, and then proceed to recommend that people actually try what is empirically the slowest options.  Please re-run the benchmarks using proper benchmarking methodology and you will see the drastic errors in your ways.

For a start, perhaps you could steal Paul M. Jones&#039;s script for benchmarking different frameworks:

http://code.google.com/p/web-framework-benchmarks/source/browse/trunk/_siege/siege.php

Related reading:

http://paul-m-jones.com/archives/421</description>
		<content:encoded><![CDATA[<p>1) If you read the benchmark carefully, you can see that in fact what you want to compare is not the apache server, but the *difference* between the speeds of PHP using the same apache setup.  Note that in each case, a single request is made to the apache server.  In other words, because all of the tests use the same apache setup, and the apache server is polled more than 10,000 times over the course of a minute, the measured difference can be reliably attributed to differences in PHP execution speed, and not in any quirks of apache.<br />
2) include/require are not functions, and if you are executing the same code over and over and over again with a single file, it will hit the realpath cache, and some other optimizations.  You benchmark is not just synthetic, it has absolutely nothing to do with real-world performance of include/require.</p>
<p>Why does this even matter?  You make some assertions with fancy charts, and then proceed to recommend that people actually try what is empirically the slowest options.  Please re-run the benchmarks using proper benchmarking methodology and you will see the drastic errors in your ways.</p>
<p>For a start, perhaps you could steal Paul M. Jones&#8217;s script for benchmarking different frameworks:</p>
<p><a href="http://code.google.com/p/web-framework-benchmarks/source/browse/trunk/_siege/siege.php" rel="nofollow">http://code.google.com/p/web-framework-benchmarks/source/browse/trunk/_siege/siege.php</a></p>
<p>Related reading:</p>
<p><a href="http://paul-m-jones.com/archives/421" rel="nofollow">http://paul-m-jones.com/archives/421</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francis</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1122</link>
		<dc:creator>Francis</dc:creator>
		<pubDate>Tue, 15 Jun 2010 08:24:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1122</guid>
		<description>@Hal / @Greg:

I agree - the test set up is totally artificial. However I wanted to look at the PHP functions themselves rather than start benchmarking the Apache server. The tests on http://markmail.org/message/hxzqcgrzrh6szce4 would be interesting to revisit today.

@Jaik:

I wouldn&#039;t be too bothered with the performance differences myself - as Greg points out including the same trivial file 10,000 times hardly demonstrates anything tangible. I prefer to code in such a way that a file only ever needs to be included once anyway (by encapsulating in a class or a function).

@Sjan:

I didn&#039;t look at __autoload() for the simple reason that I avoid using it. I did use it earlier in the Tina framework, but I found that I ended up colliding with another plugin author&#039;s __autoload() function. In an environment where everyone is playing nicely with each other I would like to use __autoload(), but in Wordpress that doesn&#039;t happen!</description>
		<content:encoded><![CDATA[<p>@Hal / @Greg:</p>
<p>I agree &#8211; the test set up is totally artificial. However I wanted to look at the PHP functions themselves rather than start benchmarking the Apache server. The tests on <a href="http://markmail.org/message/hxzqcgrzrh6szce4" rel="nofollow">http://markmail.org/message/hxzqcgrzrh6szce4</a> would be interesting to revisit today.</p>
<p>@Jaik:</p>
<p>I wouldn&#8217;t be too bothered with the performance differences myself &#8211; as Greg points out including the same trivial file 10,000 times hardly demonstrates anything tangible. I prefer to code in such a way that a file only ever needs to be included once anyway (by encapsulating in a class or a function).</p>
<p>@Sjan:</p>
<p>I didn&#8217;t look at __autoload() for the simple reason that I avoid using it. I did use it earlier in the Tina framework, but I found that I ended up colliding with another plugin author&#8217;s __autoload() function. In an environment where everyone is playing nicely with each other I would like to use __autoload(), but in Wordpress that doesn&#8217;t happen!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaik Dean</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1121</link>
		<dc:creator>Jaik Dean</dc:creator>
		<pubDate>Tue, 15 Jun 2010 08:10:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1121</guid>
		<description>Surely you should just use whichever function is relevant in each situation? If you&#039;re getting any tangible real-world performance benefit from switching between these functions then I feel your script probably has some much more serious issues that need addressing before such micro-optimisations.</description>
		<content:encoded><![CDATA[<p>Surely you should just use whichever function is relevant in each situation? If you&#8217;re getting any tangible real-world performance benefit from switching between these functions then I feel your script probably has some much more serious issues that need addressing before such micro-optimisations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hari K T</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1116</link>
		<dc:creator>Hari K T</dc:creator>
		<pubDate>Tue, 15 Jun 2010 03:42:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1116</guid>
		<description>This can be a good experiment to test the servers ;)</description>
		<content:encoded><![CDATA[<p>This can be a good experiment to test the servers <img src='http://blog.seeit.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Beaver</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1115</link>
		<dc:creator>Greg Beaver</dc:creator>
		<pubDate>Tue, 15 Jun 2010 03:02:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1115</guid>
		<description>Hi,

First of all, you can&#039;t benchmark anything properly using microtime() in PHP, the only way to accurately benchmark is to use siege, or its slightly less accurate cousin apache benchmark (ab)

I would also like to point out that no one is including a file over and over again that contains a single variable assignment.  People are including libraries with class or function code.  If you want to see a benchmark of ways of including code that also addresses the comparison of including versus stuffing it all into one file (and this one against PHP 5.3 in its pre-alpha stages), try

http://markmail.org/message/hxzqcgrzrh6szce4

for a sample.  Disclaimer: I haven&#039;t tried this benchmark in a few years, and there have been some further optimizations of PHP itself, and of how APC handles *_once.  However, the performance difference between include and include_once is not the only reason to avoid using require_once/include_once, tangled circular *_once references (like in the HTML_QuickForm package) can render a library unoptimizable by APC.

I think you&#039;ll find that your numbers are less surprising when it turns out that they are wrong :)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>First of all, you can&#8217;t benchmark anything properly using microtime() in PHP, the only way to accurately benchmark is to use siege, or its slightly less accurate cousin apache benchmark (ab)</p>
<p>I would also like to point out that no one is including a file over and over again that contains a single variable assignment.  People are including libraries with class or function code.  If you want to see a benchmark of ways of including code that also addresses the comparison of including versus stuffing it all into one file (and this one against PHP 5.3 in its pre-alpha stages), try</p>
<p><a href="http://markmail.org/message/hxzqcgrzrh6szce4" rel="nofollow">http://markmail.org/message/hxzqcgrzrh6szce4</a></p>
<p>for a sample.  Disclaimer: I haven&#8217;t tried this benchmark in a few years, and there have been some further optimizations of PHP itself, and of how APC handles *_once.  However, the performance difference between include and include_once is not the only reason to avoid using require_once/include_once, tangled circular *_once references (like in the HTML_QuickForm package) can render a library unoptimizable by APC.</p>
<p>I think you&#8217;ll find that your numbers are less surprising when it turns out that they are wrong <img src='http://blog.seeit.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hal Berner</title>
		<link>http://blog.seeit.org/2010/06/php-the-include-include_once-performance-debate/comment-page-1/#comment-1114</link>
		<dc:creator>Hal Berner</dc:creator>
		<pubDate>Mon, 14 Jun 2010 22:58:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.seeit.org/?p=23#comment-1114</guid>
		<description>If I&#039;m not mistaken, that benchmark measures how long it takes to run 10,000 include in succession, right? It doesn&#039;t seem to bear much relevance to real-world scenarios. How about some ab/siege/whatever test on 10,000 HTTP requests, each running 1 include? Or rather 10 include&#039;s on different files, because it seems like a more likely scenario.

By the way, try replacing your for loops with do{}while (--$i); where $i is initialised with the number of iterations. For some reason, do-while incurs much less overhead than for and still less than while. Or so it seems.</description>
		<content:encoded><![CDATA[<p>If I&#8217;m not mistaken, that benchmark measures how long it takes to run 10,000 include in succession, right? It doesn&#8217;t seem to bear much relevance to real-world scenarios. How about some ab/siege/whatever test on 10,000 HTTP requests, each running 1 include? Or rather 10 include&#8217;s on different files, because it seems like a more likely scenario.</p>
<p>By the way, try replacing your for loops with do{}while (&#8211;$i); where $i is initialised with the number of iterations. For some reason, do-while incurs much less overhead than for and still less than while. Or so it seems.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc (user agent is rejected)
Database Caching using apc

Served from: blog.seeit.org @ 2012-02-07 21:34:29 -->
