页面导航: 首页网络编程PHP编程php技巧 → 正文内容 php 缓存

php 缓存函数代码

发布:dxy 字体:[增加 减小] 类型:转载
简单实用的缓存函数


**
* @说明: 文件缓存输出
* @参数: $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';
}
}

Tags:php 缓存
浏览次数:载入中... 打印本文关闭本文返回首页
·在百度中搜索关于“php 缓存函数代码相关内容

文章评论

共有 位脚本之家网友发表了评论我来说两句

同 类 文 章
最 近 更 新
热 点 排 行