Creating a cache on phpWebSite
Welcome to my blog, please feel free to subscribe to my RSS feed, join me on Twitter or leave a comment.
I’ve been going nuts for the past month or so, looking for a static cache for phpWebsite, a great CMS application.
In the end, I’ve hacked together a little something and it works perfectly, all you have to do is paste this code in your index.php file, and create a file called “staticindex.html” in your root folder (chmod 777 of course).
Now, the site will check the age of staticindex.html every 5 minutes, if it’s too old it will generate a new one, otherwise it’ll serve up the static version.
if ($_GET[’cache’] == ‘1′) {
} else {
if (empty($_GET) && empty($_POST) && empty($_SESSION[”OBJ_user”])) {$fileage = date(’U’)-filemtime(’staticindex.html’);
// if it’s new, show it
if ($fileage < 300) {echo file_get_contents(’staticindex.html’);
} else {
// Open the file and erase the contents if any
$fp = fopen(“staticindex.html”, “w”);// Write the data to the file
fwrite($fp, implode(chr(13),file(‘http://www.yourwebsite.com/index.php?cache=1′)));// Close the file
fclose($fp);
echo file_get_contents(’staticindex.html’);}
die;
}}






[...] talking about templates link to One night in Paris. If you’re discussing the finer points of PHP, link to your article about it! If it was good enough to write, it should be good enough to link [...]