php 缓存函数代码
发布时间:2020-12-13 05:27:02 所属栏目:PHP教程 来源:网络整理
导读:代码如下: ** * @说明: 文件缓存输出 * @参数: $cachefile => cache文件(绝对路径) * @参数: $pertime => 缓存输出的间隔时间 * @参数: $sql => sql语句 * @参数: $templatefile => 模板文件名称(绝对路径) * www.php100.com 来自 **/ function __cache($cac
代码如下: ** * @说明: 文件缓存输出 * @参数: $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'; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |