<?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: Quick and Dirty PHP Caching</title>
	<atom:link href="http://www.snipe.net/2009/03/quick-and-dirty-php-caching/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/</link>
	<description>Bitterness never tasted so sweet</description>
	<lastBuildDate>Sat, 28 Jan 2012 01:23:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: DangerNerd</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10765</link>
		<dc:creator>DangerNerd</dc:creator>
		<pubDate>Sat, 28 Jan 2012 01:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10765</guid>
		<description>Hello there!

Thanks for making this idea so accessible.   For some reason, even though I knew this could be done, the application of it for simple caching never even popped into my head!   Simple.  Obvious.  Easy.

The quoting in your code example has been mangled (you asked us to mention if that happened again) but other than that, it all went well.

I used this as a starting point and then built automatic directory structure creation into it.   No fun having 600,000+ files in one directory.

Ended up using readfile() instead of include, and noticed a very sizable performance gain, at least in my setup.  Your concern about escaping the file could be mitigated by the fact that everything that is being output into the file should already be sanitized when written.   Upon re-insertion of that same pre-sanitized data, everything should be ok.

I also applied this to cache only certain parts of a script&#039;s output.  This way the heavy lifting portion is cached on some pages that have a lot of per-user customization,  without having to cache a different version for every user.

Thanks again for pointing me in the right direction.</description>
		<content:encoded><![CDATA[<p>Hello there!</p>
<p>Thanks for making this idea so accessible.   For some reason, even though I knew this could be done, the application of it for simple caching never even popped into my head!   Simple.  Obvious.  Easy.</p>
<p>The quoting in your code example has been mangled (you asked us to mention if that happened again) but other than that, it all went well.</p>
<p>I used this as a starting point and then built automatic directory structure creation into it.   No fun having 600,000+ files in one directory.</p>
<p>Ended up using readfile() instead of include, and noticed a very sizable performance gain, at least in my setup.  Your concern about escaping the file could be mitigated by the fact that everything that is being output into the file should already be sanitized when written.   Upon re-insertion of that same pre-sanitized data, everything should be ok.</p>
<p>I also applied this to cache only certain parts of a script&#8217;s output.  This way the heavy lifting portion is cached on some pages that have a lot of per-user customization,  without having to cache a different version for every user.</p>
<p>Thanks again for pointing me in the right direction.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordan Moore</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10641</link>
		<dc:creator>Jordan Moore</dc:creator>
		<pubDate>Sun, 27 Nov 2011 02:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10641</guid>
		<description>Does my job perfectly. Had an extremely simple script which pulled some (potentially thousands) of entries out of a database at a time, but the database wasn&#039;t frequently updated. With a bit of tweaking I&#039;ll be able to serve a cache 100% of the time and only update the cache when the database is updated - thanks!</description>
		<content:encoded><![CDATA[<p>Does my job perfectly. Had an extremely simple script which pulled some (potentially thousands) of entries out of a database at a time, but the database wasn&#8217;t frequently updated. With a bit of tweaking I&#8217;ll be able to serve a cache 100% of the time and only update the cache when the database is updated &#8211; thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ValpoCreative</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10625</link>
		<dc:creator>ValpoCreative</dc:creator>
		<pubDate>Fri, 11 Nov 2011 02:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10625</guid>
		<description>Great tutorial, I been trying to implement a nice simple cache system server side. Seems your the only developer that bothers to explain how to implement. </description>
		<content:encoded><![CDATA[<p>Great tutorial, I been trying to implement a nice simple cache system server side. Seems your the only developer that bothers to explain how to implement. </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: snipe</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10572</link>
		<dc:creator>snipe</dc:creator>
		<pubDate>Sat, 05 Nov 2011 19:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10572</guid>
		<description>Great, I&#039;ll definitely check that out, thanks!

Side note, I really hate when people use fake email addresses to leave comments. If you irrationally think I&#039;m going to do something bad with your email address, you shouldn&#039;t bother posting here, since I&#039;m obviously a piece of shit that doesn&#039;t deserve your time - or use one of the oauth options like twitter, so I never even see your email. I find using a fake one pointless and disrespectful. And more frustrating, you won&#039;t even have the option of being notified of this reply.</description>
		<content:encoded><![CDATA[<p>Great, I&#8217;ll definitely check that out, thanks!</p>
<p>Side note, I really hate when people use fake email addresses to leave comments. If you irrationally think I&#8217;m going to do something bad with your email address, you shouldn&#8217;t bother posting here, since I&#8217;m obviously a piece of shit that doesn&#8217;t deserve your time &#8211; or use one of the oauth options like twitter, so I never even see your email. I find using a fake one pointless and disrespectful. And more frustrating, you won&#8217;t even have the option of being notified of this reply.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Youwontgetmyemail</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10571</link>
		<dc:creator>Youwontgetmyemail</dc:creator>
		<pubDate>Sat, 05 Nov 2011 15:51:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10571</guid>
		<description>Hey, tried it - really cool!
I have an addition to your list of caching libraries: Zoocache is very easy to integrate into an application and you can choose a method to store your contents in. Also nice: It provides a blacklist using RegExp and you can write your own function to generate the storage key. This makes it possible to deliver different versions of the page for e.g. different webbrowsers! Hosted at: http://gihub.com/marcelklehr/zoocache.php</description>
		<content:encoded><![CDATA[<p>Hey, tried it &#8211; really cool!<br />
I have an addition to your list of caching libraries: Zoocache is very easy to integrate into an application and you can choose a method to store your contents in. Also nice: It provides a blacklist using RegExp and you can write your own function to generate the storage key. This makes it possible to deliver different versions of the page for e.g. different webbrowsers! Hosted at: <a href="http://gihub.com/marcelklehr/zoocache.php" rel="nofollow">http://gihub.com/marcelklehr/zoocache.php</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Teguh Budimulia</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10513</link>
		<dc:creator>Teguh Budimulia</dc:creator>
		<pubDate>Tue, 20 Sep 2011 06:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10513</guid>
		<description>Awesome. I&#039;ll take the code :)</description>
		<content:encoded><![CDATA[<p>Awesome. I&#8217;ll take the code <img src='http://www.snipe.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: snipe</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10458</link>
		<dc:creator>snipe</dc:creator>
		<pubDate>Mon, 13 Jun 2011 19:47:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10458</guid>
		<description>Dear &quot;stop@stealing.com&quot; - I&#039;ve never seen that article before, and the two are nothing like each other. Do they cover the same things? Absolutely - it&#039;s a freaking caching article - output buffering is sort of going to come up, and it&#039;s going to be handled the same way every time. All ob caching articles are going to cover similar things because it&#039;s done the same way every time. Duh.</description>
		<content:encoded><![CDATA[<p>Dear &#8220;stop@stealing.com&#8221; &#8211; I&#8217;ve never seen that article before, and the two are nothing like each other. Do they cover the same things? Absolutely &#8211; it&#8217;s a freaking caching article &#8211; output buffering is sort of going to come up, and it&#8217;s going to be handled the same way every time. All ob caching articles are going to cover similar things because it&#8217;s done the same way every time. Duh.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10457</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 13 Jun 2011 18:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10457</guid>
		<description>Wow, you were inspired a little too much from the original article it seems;

http://www.theukwebdesigncompany.com/articles/php-caching.php</description>
		<content:encoded><![CDATA[<p>Wow, you were inspired a little too much from the original article it seems;</p>
<p><a href="http://www.theukwebdesigncompany.com/articles/php-caching.php" rel="nofollow">http://www.theukwebdesigncompany.com/articles/php-caching.php</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sven</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-10266</link>
		<dc:creator>Sven</dc:creator>
		<pubDate>Wed, 02 Feb 2011 07:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-10266</guid>
		<description>Cacheing and reading from PHP is not bad, but using more advanced methods and going around PHP can bring you a much better performance. I did a benchmark on my blog there I compared reading cache from PHP and reading cache from Apache, you can read more about it here:
http://sven.webiny.com/advanced-cache-mechanism-using-php-cpp-and-apache/ </description>
		<content:encoded><![CDATA[<p>Cacheing and reading from PHP is not bad, but using more advanced methods and going around PHP can bring you a much better performance. I did a benchmark on my blog there I compared reading cache from PHP and reading cache from Apache, you can read more about it here:<br />
<a href="http://sven.webiny.com/advanced-cache-mechanism-using-php-cpp-and-apache/" rel="nofollow">http://sven.webiny.com/advanced-cache-mechanism-using-php-cpp-and-apache/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aussiedude</title>
		<link>http://www.snipe.net/2009/03/quick-and-dirty-php-caching/comment-page-2/#comment-8888</link>
		<dc:creator>Aussiedude</dc:creator>
		<pubDate>Thu, 12 Aug 2010 16:58:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.snipe.net/?p=1698#comment-8888</guid>
		<description>Just incase it helps anyone, I&#039;ve been doing my homework on this for a while now, so I can create an effective template/cache system for my site I&#039;m writing right now (in PHP from scratch, it&#039;s really more of a personal learning experience, teaching myself PHP while making a site at the same time).

I&#039;ve designed my template system to build the page from small templated components that are combined together to form the whole page. Such as one template for how to display dialog messages, comments, profiles, menu&#039;s, etc.

That way, if the page being requested was requested before, and the output is exactly the same for both, it&#039;ll use a cached version of the entire page.

However, if not, it&#039;ll use cached versions of certain parts of the page, and for the rest it&#039;ll just make it up as it&#039;s needed. 

(However the downside to this is, for whole page caching situations, it&#039;ll still need to build the little components first before it builds the entire thing, but at least it&#039;ll be making the little components from the cache. Optimally, it&#039;d be best if it could go just straight to the full page cache, but it&#039;s better than nothing for now until I can find a solution for that.)

My templates just use PHP and the output buffer, I didn&#039;t write my own tag system or anything, so all my templates are just php files in a template folder I load using my website&#039;s main &quot;engine&quot; (if it could be called that?). The variables for the template are just based through in a single associative array.

Which makes it easy to tell if a cached version of the template can be used or not. I&#039;ve got a folder called &#039;cache&#039;, where versions of each template are stored, with the name of the php file, followed by a short hash of the array&#039;s contents, and unix timestamp. 

Example of a cache file for a template called &#039;poll-view.php&#039;:
poll-view.d81cfdaaa2.1281634990.php

(Format: file-name.10-character-hash.unix-time-stamp.php)

If the same array values are passed to the same template, the output will be the same every time. Hence, if two hashes of the array are the same then it&#039;s highly likely the two hashed arrays have the same contents. (As for hashing the array, I just implode it, use md5, then grab the first 10 characters).

As for how long to keep it for, I also included as you can see, a unix time stamp in the cache files name. When a new cache file needs to be added, a check is done to see if the folder has too much in it, if so, the oldest cache files are removed, until there is enough space. 

Though I haven&#039;t finished that part of the code. Not sure if I&#039;ll make it remove a template when the folder is above a certain number of MB&#039;s, or just based on file count. MB&#039;s would be better I&#039;m guessing, but it depends on how easy it is to do that over counting the number of files in the folder.

Even still, that does mean for each template component, it&#039;s going to do a fair bit of work to add that cache file. So I&#039;m thinking that might be something for a cron job to do.. 

The only real benefit I see myself getting from it all is if I store a lot of cached templates, and if most of the requests use existing cached versions of the templates. If not, I think it might actually make my website slower. But I&#039;m designing it to have an on/off feature, so I can experiment, see if it speeds up the website any, and if so, I&#039;ll use it.

So, if you&#039;re currently making a website that needs caching right now, hope that helps! :3

(Sorry for the length of the post and the typos)</description>
		<content:encoded><![CDATA[<p>Just incase it helps anyone, I&#8217;ve been doing my homework on this for a while now, so I can create an effective template/cache system for my site I&#8217;m writing right now (in PHP from scratch, it&#8217;s really more of a personal learning experience, teaching myself PHP while making a site at the same time).</p>
<p>I&#8217;ve designed my template system to build the page from small templated components that are combined together to form the whole page. Such as one template for how to display dialog messages, comments, profiles, menu&#8217;s, etc.</p>
<p>That way, if the page being requested was requested before, and the output is exactly the same for both, it&#8217;ll use a cached version of the entire page.</p>
<p>However, if not, it&#8217;ll use cached versions of certain parts of the page, and for the rest it&#8217;ll just make it up as it&#8217;s needed. </p>
<p>(However the downside to this is, for whole page caching situations, it&#8217;ll still need to build the little components first before it builds the entire thing, but at least it&#8217;ll be making the little components from the cache. Optimally, it&#8217;d be best if it could go just straight to the full page cache, but it&#8217;s better than nothing for now until I can find a solution for that.)</p>
<p>My templates just use PHP and the output buffer, I didn&#8217;t write my own tag system or anything, so all my templates are just php files in a template folder I load using my website&#8217;s main &#8220;engine&#8221; (if it could be called that?). The variables for the template are just based through in a single associative array.</p>
<p>Which makes it easy to tell if a cached version of the template can be used or not. I&#8217;ve got a folder called &#8216;cache&#8217;, where versions of each template are stored, with the name of the php file, followed by a short hash of the array&#8217;s contents, and unix timestamp. </p>
<p>Example of a cache file for a template called &#8216;poll-view.php&#8217;:<br />
poll-view.d81cfdaaa2.1281634990.php</p>
<p>(Format: file-name.10-character-hash.unix-time-stamp.php)</p>
<p>If the same array values are passed to the same template, the output will be the same every time. Hence, if two hashes of the array are the same then it&#8217;s highly likely the two hashed arrays have the same contents. (As for hashing the array, I just implode it, use md5, then grab the first 10 characters).</p>
<p>As for how long to keep it for, I also included as you can see, a unix time stamp in the cache files name. When a new cache file needs to be added, a check is done to see if the folder has too much in it, if so, the oldest cache files are removed, until there is enough space. </p>
<p>Though I haven&#8217;t finished that part of the code. Not sure if I&#8217;ll make it remove a template when the folder is above a certain number of MB&#8217;s, or just based on file count. MB&#8217;s would be better I&#8217;m guessing, but it depends on how easy it is to do that over counting the number of files in the folder.</p>
<p>Even still, that does mean for each template component, it&#8217;s going to do a fair bit of work to add that cache file. So I&#8217;m thinking that might be something for a cron job to do.. </p>
<p>The only real benefit I see myself getting from it all is if I store a lot of cached templates, and if most of the requests use existing cached versions of the templates. If not, I think it might actually make my website slower. But I&#8217;m designing it to have an on/off feature, so I can experiment, see if it speeds up the website any, and if so, I&#8217;ll use it.</p>
<p>So, if you&#8217;re currently making a website that needs caching right now, hope that helps! :3</p>
<p>(Sorry for the length of the post and the typos)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.290 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-01-31 01:36:57 -->

