首頁  >  文章  >  後端開發  >  php 缓存函数代码_PHP教程

php 缓存函数代码_PHP教程

WBOY
WBOY原創
2016-07-21 15:49:55751瀏覽

复制代码 代码如下:

**
* @说明: 文件缓存输出
* @参数: $cachefile => cache文件(绝对路径)
* @参数: $pertime => 缓存输出的间隔时间
* @参数: $sql => sql语句
* @参数: $templatefile => 模板文件名称(绝对路径)
* www.php100.com 来自
**/
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/319461.htmlTechArticle复制代码 代码如下: ** * @说明: 文件缓存输出 * @参数: $cachefile = cache文件(绝对路径) * @参数: $pertime = 缓存输出的间隔时间 * @参数: $sql = sq...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn