$max_age) { //echo "unlinking ".getcwd()."/$file\n"; @unlink($file); } } } @closedir($handle); } chdir($start_dir); } function start_cache($max_age, $params=""){ $path = get_path($params); // check free disk space every once in a while // if (!(rand() % CACHE_SIZE_CHECK_FREQ)) { $too_old=86400; while ((disk_free_space("../cache") < MIN_FREE_SPACE) || (disk_usage("../cache") > MAX_CACHE_USAGE)) { clean_cache($too_old, "../cache"); $too_old/=2; } } $regenerate = false; if ($max_age) { $request = getallheaders(); $lastmodified = @filemtime($path); if ($lastmodified) { // Check to see if this is a conditional fetch. // $if_modified_since = isset($request['If-Modified-Since']) ? (explode(';',$request['If-Modified-Since'])) : false; if ($if_modified_since) { $if_modified_since=strtotime($if_modified_since[0]); } if ($if_modified_since && ($if_modified_since == $lastmodified)) { Header("Last-Modified: " . gmdate("D, d M Y H:i:s",$lastmodified) . " GMT"); Header('HTTP/1.0 304 Not Modified'); exit; } // See if cached copy is too old. // If so regenerate, // and touch the cached copy so other processes // don't regenerate at the same time // if ($lastmodifiedGenerated ",time_str(time()),"\n"; if ($max_age) { $path = get_path($params); $fhandle=fopen($path, "w"); $page=ob_get_contents(); ob_end_flush(); fwrite($fhandle, $page); fclose($fhandle); } } ?>