<?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>The Digital Life of Keith Baker.&#187; php Archives  &#8211; iKeif &#8211; tech and social media geek, mootools fan, and a ton of links</title>
	<atom:link href="http://ikeif.net/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://ikeif.net</link>
	<description>iKeif.net - Web developer, father, and brewer.</description>
	<lastBuildDate>Sat, 08 May 2010 03:07:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Stop Caching Old Files &#8211; A PHP Function</title>
		<link>http://ikeif.net/2009/03/27/stop-caching-files-php-function/</link>
		<comments>http://ikeif.net/2009/03/27/stop-caching-files-php-function/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 09:52:31 +0000</pubDate>
		<dc:creator>keif</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://ikeif.net/?p=404</guid>
		<description><![CDATA[It&#8217;s weird that I swear David Walsh follows me around &#8211; everytime I have a conversation with someone about something, he writes an article about it &#8211; like preventing your css and javascript from being cached.
I had come to the same conclusion (from by conversation with Toby) that random querystrings being appended didn&#8217;t make much [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>It&#8217;s weird that I swear David Walsh follows me around &#8211; everytime I have a conversation with someone about something, he writes an article about it &#8211; like <a href="http://davidwalsh.name/prevent-cache">preventing your css and javascript from being cached</a>.</p>
<p>I had come to the same conclusion (from by conversation with <a href="http://www.tobymiller.com">Toby</a>) that random querystrings being appended didn&#8217;t make much sense &#8211; that prevents caching, but why stop caching &#8211; unless the file gets updated?</p>
<p>I wrote a little php function that works with <a href="http://us.php.net/function.filemtime">filemtime</a>, albeit it requires the absolute path of the file.</p>
<p>[code lang="php"]</p>
<p>function autoVer($url){<br />
$path = pathinfo($url);<br />
$ver = '.'.filemtime($_SERVER['DOCUMENT_ROOT'].$url);<br />
echo $path['dirname'].'/'.$path['basename'].'?'.$ver;<br />
}</p>
<p>[/code]</p>
<p>What this means, is when we call our files like so:</p>
<p>[code lang="php"]</p>
<link rel="stylesheet" type="text/css" href="<?php autoVer('/mootools/css/reset.css') ?>" /><br />
[/code]</p>
<p>It renders like so:</p>
<p>[code lang="php"]</p>
<link rel="stylesheet" type="text/css" href="/mootools/css/reset.css?1224038981" />
<p>[/code]</p>
<p>So only when your file gets updated, does the query update, forcing the cache invalid!</p>
<p>It&#8217;s a simple function &#8211; and by no means perfect. Would you refactor it, or do you have a better way?</link>
<hr/>Copyright &copy; 2010 <strong><a href="http://ikeif.net">The Digital Life of Keith Baker.</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@ikeif.net so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://ikeif.net/2009/03/27/stop-caching-files-php-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
