php 缓存函数代码

yipeiwu_com6年前PHP代码库

复制代码 代码如下:

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

相关文章

The specified CGI application misbehaved by not returning a complete set of HTTP headers

是错误报告: The specified CGI application misbehaved by not returning a complete set of HTTP heade...

php防止恶意刷新与刷票的方法

本文实例讲述了php防止恶意刷新与刷票的方法。分享给大家供大家参考。具体实现方法如下: 一般来说,恶意刷新就是不停的去刷新提交页面,导致出现大量无效数据,下面我们来总结一下php 防止恶...

php简单判断两个字符串是否相等的方法

本文实例讲述了php简单判断两个字符串是否相等的方法。分享给大家供大家参考。具体实现方法如下: <?php function strcomp($str1,$str2)...

php流量统计功能的实现代码

流量统计功能 显示效果: 总访问量:399 今日流量:14 昨日流量:16 本代码仅供学习交流,其中必有不妥之处。请见谅! -- -- 表的结构 `mycounter` -- 复制代码...

PHP实现字节数Byte转换为KB、MB、GB、TB的方法 原创

PHP实现字节数Byte转换为KB、MB、GB、TB的方法 原创

本文实例讲述了PHP实现字节数Byte转换为KB、MB、GB、TB的方法。分享给大家供大家参考,具体如下: 前面介绍了java实现字节数Byte转换为KB、MB、GB、TB的方法 ,这里...