2004-06-09 21:42:23 +00:00
|
|
|
<?php
|
2004-04-14 20:55:37 +00:00
|
|
|
|
|
|
|
// mechanism for caching commonly-accessed pages
|
|
|
|
|
2004-06-10 19:43:54 +00:00
|
|
|
function get_path($params) {
|
|
|
|
$y = pathinfo($_SERVER["PHP_SELF"]);
|
|
|
|
$z = $y["basename"];
|
|
|
|
$path = "../cache/".$z;
|
|
|
|
if ($params) {
|
|
|
|
$path = $path."_".urlencode($params);
|
|
|
|
}
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
function start_cache($max_age, $params=""){
|
|
|
|
$path = get_path($params);
|
2004-04-14 20:55:37 +00:00
|
|
|
|
|
|
|
if (@filemtime($path)<time()-$max_age){
|
|
|
|
// If cached version is too old (or non-existent)
|
|
|
|
// generate the page and write to cache
|
|
|
|
//
|
|
|
|
ob_start();
|
|
|
|
ob_implicit_flush(0);
|
|
|
|
} else {
|
|
|
|
// Otherwise serve the cached version and exit
|
|
|
|
//
|
|
|
|
readfile($path);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// write output buffer both to client and to cache
|
|
|
|
//
|
2004-06-10 19:43:54 +00:00
|
|
|
function end_cache($params=""){
|
|
|
|
$path = get_path($params);
|
2004-04-14 20:55:37 +00:00
|
|
|
$fhandle=fopen($path, "w");
|
|
|
|
$page=ob_get_contents();
|
|
|
|
ob_end_flush();
|
|
|
|
fwrite($fhandle, $page);
|
|
|
|
fclose($fhandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|