<?xml version="1.0" ?>
<rss version="2.0">
	<channel>
		<title>Keith's Weblog: Comments on &quot;Building large strings in PHP&quot;</title>
		<description>Keith's Weblog: Comments on &quot;Building large strings in PHP&quot;, posted on May 28, 2004</description>
		<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings</link>

		<category>Programming</category>
		<language>en-us</language>
		<image>
			<link>http://keithdevens.com/weblog</link>
			<title>Keith Devens .com</title>
			<url>http://keithdevens.com/images/kbd.gif</url>
		</image>

		<item>
			<title>by Adam Langley</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment4697</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment4697</guid>
			<pubDate>Sat, 29 May 2004 10:02:22 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;Though this is &lt;em&gt;not&lt;/em&gt; true in Python.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;AGL&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Joshua Paine</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment4704</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment4704</guid>
			<pubDate>Mon, 31 May 2004 00:19:48 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;The absolute fastest is to use output buffering. Start a buffer, echo/print everything to output, then pour the buffer into a variable. Slightly but noticeably faster than concatenating--strange but true.&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Keith</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment4706</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment4706</guid>
			<pubDate>Tue, 01 Jun 2004 02:50:55 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;Thanks Joshua, I'll have to time it that way as well and publish my results.&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Keith</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment4730</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment4730</guid>
			<pubDate>Sat, 05 Jun 2004 00:32:24 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;Hey Joshua, you were right. Not as much of a difference from concatenating to output buffering as it was from building arrays to concatenating, but it did make a difference. Plus, it's often less to type as well. Thanks.&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by John Lim</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment4735</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment4735</guid>
			<pubDate>Mon, 07 Jun 2004 16:27:58 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;Hi Keith,&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;Neat trick. I was intrigued enough to check the PHP source code.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;A look at output.c shows that ob_start() allocates an enormous 40K buffer for strings. And each time the buffer needs to grow, it does it in chunks of 10K.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;John&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Erik</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment4739</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment4739</guid>
			<pubDate>Tue, 08 Jun 2004 04:01:35 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;A noob request, but could you show the source code as to how output buffering is done?&lt;/p&gt;

&lt;blockquote class=&quot;st-markup&quot;&gt;&lt;p&gt;The absolute fastest is to use output buffering. Start a buffer, echo/print everything to output, then pour the buffer into a variable&lt;/p&gt;&lt;/blockquote&gt;

</description>
		</item>
		<item>
			<title>by Keith</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment4740</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment4740</guid>
			<pubDate>Tue, 08 Jun 2004 04:10:53 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;No problem. The best thing for me to do is point you to my &lt;a href=&quot;/software/phpxml&quot;&gt;XML library&lt;/a&gt; (source &lt;a href=&quot;/software/phpxml/xml.phps&quot;&gt;here&lt;/a&gt;). I use this technique in the XML_serialize function.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;The relevant lines are as follows:&lt;/p&gt;

&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;ob_start&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;#output&amp;#160;here&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$str&amp;#160;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&amp;#160;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;ob_get_contents&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;ob_end_clean&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;();&lt;br /&gt;return&amp;#160;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$str&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/code&gt;&lt;p class=&quot;st-markup&quot;&gt;Or, if you just want to output the string rather than returning it, you can replace ob_get_contents() and ob_end_clean() with ob_end_flush(). You could also replace the combination of ob_get_contents() and ob_end_clean() with ob_get_clean() if you're using PHP 4.3.0 or above. See PHP's documentation at &lt;a href=&quot;http://php.net/outcontrol&quot;&gt;http://php.net/outcontrol&lt;/a&gt;&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Claudex</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment4741</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment4741</guid>
			<pubDate>Tue, 08 Jun 2004 08:36:40 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;With 100 iterations on my Athlon 2000XP, with Windows Xp:&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;Append:0.001133&lt;br /&gt;
Implode:0.003901&lt;br /&gt;
OB:0.000870&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by </title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment10325</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment10325</guid>
			<pubDate>Fri, 05 Oct 2007 14:28:30 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;100 operations? Is that supposed to be funny?&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;Do at least a billion - counting microseconds is stupid - unless you write &amp;quot;0.001 +/- 100%&amp;quot;.&lt;/p&gt;

&lt;p class=&quot;st-markup&quot;&gt;Yes, the error can be this big.&lt;/p&gt;

</description>
		</item>
		<item>
			<title>by Php</title>
			<link>http://keithdevens.com/weblog/archive/2004/May/28/PHP.building-strings#comment11277</link>
			<guid isPermaLink="false">http://keithdevens.com/weblog/4934#comment11277</guid>
			<pubDate>Thu, 23 Jul 2009 09:53:16 +0000</pubDate>
			<description>&lt;p class=&quot;st-markup&quot;&gt;If absolute fastest use output buffering and use buffer into variable the string concatenating is slightly faster.&lt;/p&gt;

</description>
		</item>
	</channel>
</rss>
