php 缓存函数代码_php教程-查字典教程网
php 缓存函数代码
php 缓存函数代码
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:***@说明:文件缓存输出*@参数:$cachefile=>cache文件(绝对路径)*@参数:$pertime=>缓存输...

复制代码 代码如下:

**

* @说明: 文件缓存输出

* @参数: $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';

}

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类