I followed this tutorial on the caching function. I ran into the problem of passing a callback function cache_page()to ob_start. How to pass cache_page()along with two parameters $midand $pathon ob_start, something along the lines
ob_start("cache_page($mid,$path)");
Of course, the above will not work. Here is a sample code:
$mid = $_GET['mid'];
$path = "cacheFile";
define('CACHE_TIME', 12);
function cache_file($p,$m)
{
return "directory/{$p}/{$m}.html";
}
function cache_display($p,$m)
{
$file = cache_file($p,$m);
if(!file_exists($file)) return;
if(filemtime($file) < time() - CACHE_TIME * 3600) return;
header('Content-Encoding: gzip');
echo gzuncompress(file_get_contents($file));
exit;
}
function cache_page($content,$p,$m)
{
if(false !== ($f = @fopen(cache_file($p,$m), 'w'))) {
fwrite($f, gzcompress($content));
fclose($f);
}
return $content;
}
cache_display($path,$mid);
ob_start("cache_page");
source
share