I've been following this tutorial on a caching function. I run into a problem of passing the callback function cache_page()
for ob_start
. How can I pass cache_page()
along with two paramters $mid
and $path
to ob_start
, something along the lines of
ob_start("cache_page($mid,$path)");
Of course the above won't work. Here's the example 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);
// check that cache file exists and is not too old
if(!file_exists($file)) return;
if(filemtime($file) < time() - CACHE_TIME * 3600) return;
header('Content-Encoding: gzip');
// if so, display cache file and stop processing
echo gzuncompress(file_get_contents($file));
exit;
}
// write to cache file
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"); ///// here's the problem
cache_page
function is supposed to do? I see it requires three arguments but you are only passing two arguments in theob_start
call. Likewise, the callback forob_start
has to have the signaturestring handler ( string $buffer [, int $phase ] )
– Hypoacidity