当前位置:Gxlcms > PHP教程 > 简单实用的php缓存函数_PHP教程

简单实用的php缓存函数_PHP教程

时间:2021-07-01 10:21:17 帮助过:2人阅读

/**
* @说明: 文件缓存输出
* @参数: $cachefile => cache文件(绝对路径)
* @参数: $pertime => 缓存输出的间隔时间
* @参数: $sql => sql语句
* @参数: $templatefile => 模板文件名称(绝对路径)
**/
function __cache($cachefile,$pertime,$sql,$templatefile) {
global $db;
if(time() - @filemtime($cachefile) >= $pertime) {
$query = $db->query($sql);
while($r=$db->fetch($query)) {
$cachelist[] = $r;
}
include $templatefile..php;
$cacheserialize = serialize($cachelist);
file_put_contents($cachefile,$cacheserialize);
}else{
$cachelist = unserialize(file_get_contents($cachefile));
include $templatefile..php;
}
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/508228.htmlTechArticle/** * @说明: 文件缓存输出 * @参数: $cachefile = cache文件(绝对路径) * @参数: $pertime = 缓存输出的间隔时间 * @参数: $sql = sql语句 * @参数: $templa...

人气教程排行