标签:php页面缓存的使用方法
<?php
/**ob_start();
ob_get_contents();
ob_end_flush();
**
**php页面缓存的使用方法,php页面缓存的小例子,如果数据库查询量较大,可以用cache来解决
**/
function cache_start($dir,$expiretime){
$filename = $dir.‘\\‘.sha1($_SERVER[‘REQUEST_URI‘]).‘.html‘;
ob_start();
if(file_exists($filename) && (time()- filemtime($filename)<$expiretime)){
include($filename);
ob_end_flush();
exit();
}
mkdir($dir);
}
function cache_end($dir){
$filename = $dir.‘\\‘.sha1($_SERVER[‘REQUEST_URI‘]).‘.html‘;
echo $filename;
$fp = fopen($filename,‘w‘);
fwrite($fp,ob_get_contents());
fclose($fp);
ob_end_flush();
}
$dir = "D:\\\\php";
cache_start($dir, 10);
cache_end($dir);本文出自 “王尼美的成人之路” 博客,请务必保留此出处http://8335914.blog.51cto.com/8325914/1582904
标签:php页面缓存的使用方法
原文地址:http://8335914.blog.51cto.com/8325914/1582904