Return to Snippet

Revision: 12166
at March 4, 2009 14:23 by iTony


Initial Code
$cacheFile = 'cache/index-cached.html';
$cacheTime = 4 * 60;
// Serve the cached file if it is older than $cacheTime
if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) {
    include($cacheFile);
    exit;
}
// Start the output buffer
ob_start();

/* Heres where you put your page content */

// Cache the contents to a file
$cached = fopen($cacheFile, 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Send the output to the browser

Initial URL
http://papearmashup.com/caching-dynamic-php-pages-easily

Initial Description


Initial Title
Simple Page Caching

Initial Tags
php, cache

Initial Language
PHP