<?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: Speeding Things with PHP Output Buffer</title>
	<atom:link href="http://planetozh.com/blog/2006/05/speeding-things-with-php-output-buffer/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetozh.com/blog/2006/05/speeding-things-with-php-output-buffer/?source=rss</link>
	<description>A bit of my personal life, mainly focused on my kids. A bit of code, mainly focused on Wordpress and PHP. Overall, bits of nothing in particular.</description>
	<lastBuildDate>Fri, 18 May 2012 15:58:55 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Ozh</title>
		<link>http://planetozh.com/blog/2006/05/speeding-things-with-php-output-buffer/comment-page-1/#comment-101374</link>
		<dc:creator>Ozh</dc:creator>
		<pubDate>Mon, 15 Mar 2010 07:11:52 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/05/05/speeding-things-with-php-output-buffer/#comment-101374</guid>
		<description>Will Anderson » hey Will thanks for commenting on this 4 yo post :) Yeah, my interpretation was something similar, but for some reason (at that time at least) I was a bit scared by OB, it seemed to me that would be a slow beast.</description>
		<content:encoded><![CDATA[<p>Will Anderson » hey Will thanks for commenting on this 4 yo post :) Yeah, my interpretation was something similar, but for some reason (at that time at least) I was a bit scared by OB, it seemed to me that would be a slow beast.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will Anderson</title>
		<link>http://planetozh.com/blog/2006/05/speeding-things-with-php-output-buffer/comment-page-1/#comment-101356</link>
		<dc:creator>Will Anderson</dc:creator>
		<pubDate>Mon, 15 Mar 2010 00:25:01 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/05/05/speeding-things-with-php-output-buffer/#comment-101356</guid>
		<description>OK, so this is a ~4 year old post, so I feel sort of silly commenting on it, but since you linked to it on Twitter I thought I&#039;d throw my own two cents into the interpretation of the outcome.

In your first example, the reason buffering performs better is not because output buffering in itself is more efficient.  in fact, the opposite is generally true, especially when memory consumption is considered.

The reason the first example ran faster with output buffering is because of the way string concatenation works in PHP (and most other languages). Strings aren&#039;t mutable, so when you concatenate two strings, a completely new string is created in memory and the contents of the other two strings are copped into the new string. Do this several thousand times and you can start to see the inefficiency that this causes.

Most other languages offer a &quot;string buffering&quot; classes like StringBuffer in Java and StringBuilder in C#. As far as I know, PHP doesn&#039;t offer a facility like this, so using output buffering could be the way to go, but only in this specific case (where you&#039;re concatenating lots of strings). In general, output buffering will be much slower, as you saw in your other example.

I&#039;d also note that the reason the &#039;include&#039; method was so much slower in the second example because it was executed in the PHP interpreter context, which goes MUCH slower than simply reading in the bytes (because PHP has to actually evaluate the file to see if there is any code that needs to be executed).

At any rate, those are my thoughts on output buffering. There are certainly places where it is useful, but in general it doesn&#039;t improve performance at all.</description>
		<content:encoded><![CDATA[<p>OK, so this is a ~4 year old post, so I feel sort of silly commenting on it, but since you linked to it on Twitter I thought I&#8217;d throw my own two cents into the interpretation of the outcome.</p>
<p>In your first example, the reason buffering performs better is not because output buffering in itself is more efficient.  in fact, the opposite is generally true, especially when memory consumption is considered.</p>
<p>The reason the first example ran faster with output buffering is because of the way string concatenation works in PHP (and most other languages). Strings aren&#8217;t mutable, so when you concatenate two strings, a completely new string is created in memory and the contents of the other two strings are copped into the new string. Do this several thousand times and you can start to see the inefficiency that this causes.</p>
<p>Most other languages offer a &#8220;string buffering&#8221; classes like StringBuffer in Java and StringBuilder in C#. As far as I know, PHP doesn&#8217;t offer a facility like this, so using output buffering could be the way to go, but only in this specific case (where you&#8217;re concatenating lots of strings). In general, output buffering will be much slower, as you saw in your other example.</p>
<p>I&#8217;d also note that the reason the &#8216;include&#8217; method was so much slower in the second example because it was executed in the PHP interpreter context, which goes MUCH slower than simply reading in the bytes (because PHP has to actually evaluate the file to see if there is any code that needs to be executed).</p>
<p>At any rate, those are my thoughts on output buffering. There are certainly places where it is useful, but in general it doesn&#8217;t improve performance at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrey</title>
		<link>http://planetozh.com/blog/2006/05/speeding-things-with-php-output-buffer/comment-page-1/#comment-42287</link>
		<dc:creator>Andrey</dc:creator>
		<pubDate>Sun, 02 Dec 2007 17:58:14 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/05/05/speeding-things-with-php-output-buffer/#comment-42287</guid>
		<description>In rare cases it can be very bad, especially with shared hosting with limited RAM given for PHP.
Also if script crashes somewhere between ob_start and ob_get_contents there won&#039;t be any output at all, so user will see blank page.
but OB still lovely thing :)</description>
		<content:encoded><![CDATA[<p>In rare cases it can be very bad, especially with shared hosting with limited RAM given for PHP.<br />
Also if script crashes somewhere between ob_start and ob_get_contents there won&#8217;t be any output at all, so user will see blank page.<br />
but OB still lovely thing :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eff</title>
		<link>http://planetozh.com/blog/2006/05/speeding-things-with-php-output-buffer/comment-page-1/#comment-37372</link>
		<dc:creator>eff</dc:creator>
		<pubDate>Sun, 22 Jul 2007 22:02:57 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/05/05/speeding-things-with-php-output-buffer/#comment-37372</guid>
		<description>ob_start is great -- it&#039;s also a great way to handle exceptions: if something throws an exception while you are filling your buffer, you can print custom error pages, etc. 

thanks for the writeup.</description>
		<content:encoded><![CDATA[<p>ob_start is great &#8212; it&#8217;s also a great way to handle exceptions: if something throws an exception while you are filling your buffer, you can print custom error pages, etc. </p>
<p>thanks for the writeup.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sanjay shah</title>
		<link>http://planetozh.com/blog/2006/05/speeding-things-with-php-output-buffer/comment-page-1/#comment-24426</link>
		<dc:creator>sanjay shah</dc:creator>
		<pubDate>Mon, 19 Jun 2006 12:11:01 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/05/05/speeding-things-with-php-output-buffer/#comment-24426</guid>
		<description>hi 
Can we pass buffer to the readfile() function 
eg. readfile($buffer) //where $buffer is a output buffer got from

$buffer=ob_get_contents();


can it(readfile()) also be  used to push contents of buffer to output(brower) any other ...</description>
		<content:encoded><![CDATA[<p>hi<br />
Can we pass buffer to the readfile() function<br />
eg. readfile($buffer) //where $buffer is a output buffer got from</p>
<p>$buffer=ob_get_contents();</p>
<p>can it(readfile()) also be  used to push contents of buffer to output(brower) any other &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kates</title>
		<link>http://planetozh.com/blog/2006/05/speeding-things-with-php-output-buffer/comment-page-1/#comment-8786</link>
		<dc:creator>Kates</dc:creator>
		<pubDate>Wed, 10 May 2006 08:02:18 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/05/05/speeding-things-with-php-output-buffer/#comment-8786</guid>
		<description>Good to know I&#039;m not alone in this profiling and discovering stuff thing in PHP. It&#039;s only now that I actually know what ob_start() is for. All the while I thought ob stands for object. Oh, well.</description>
		<content:encoded><![CDATA[<p>Good to know I&#8217;m not alone in this profiling and discovering stuff thing in PHP. It&#8217;s only now that I actually know what ob_start() is for. All the while I thought ob stands for object. Oh, well.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

