首页 > Web开发 > 详细

PHP简单实用的缓存函数

时间:2015-01-07 18:25:28      阅读:295      评论:0      收藏:0      [点我收藏+]
/**
* @说明: 文件缓存输出
* @参数: $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‘;
}
}

 

PHP简单实用的缓存函数

原文:http://www.cnblogs.com/itcx/p/4209015.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!