$max_age) { //echo "unlinking ".getcwd()."/$file\n"; @unlink($file); } } } @closedir($handle); } chdir($start_dir); } // check free disk space every once in a while function cache_check_diskspace(){ if (!(rand() % CACHE_SIZE_CHECK_FREQ)) { set_time_limit(0); // this may take a while $max_age = 86400; while ((disk_free_space("../cache") < MIN_FREE_SPACE) || (disk_usage("../cache") > MAX_CACHE_USAGE) ) { clean_cache($max_age, "../cache"); $max_age/=2; } } } function cache_need_to_regenerate($path, $max_age){ $regenerate = false; $request = apache_request_headers(); clearstatcache(); $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 ($lastmodified