特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> 网络编程教程> 简单实用的php缓存函数

简单实用的php缓存函数

时间:2009-06-06 18:17:45 作者:互联网
/**
 * @说明: 文件缓存输出
 * @参数: $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';
 }
}
相关文章

相关应用

热门文章

猜你喜欢

返回顶部