Home > php教程 > php手册 > body text

简单实用的php缓存函数

WBOY
Release: 2016-06-13 10:35:06
Original
861 people have browsed it

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!