$cacheid=md5(preg_replace('/timestamp=([d|-]+)([d|:]+)/i','',$url));
$dirpath = substr($cacheid,0,1);
$file =substr($cacheid,0,1).'/'.$cacheid;
$cachetime =24*3600;
if(file_exists($file) && (time() - date('U',@filemtime($file))) < $cachetime){
$result =@file_get_contents($file);
}
else{
$result = @file_get_contents($url);
@mkdir($dirpath);
@file_put_contents($file,$result);
}
这样不用频繁用到动态页面减轻数据库压力!
评论