php 缓存函数代码

yipeiwu_com5年前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';
}
}

相关文章

php中几种常见安全设置详解

另外,目前闹的轰轰烈烈的SQL Injection也是在PHP上有很多利用方式,所以要保证安全,PHP代码编写是一方面,PHP的配置更是非常关键。 我们php手手工安装的,php的默认...

php eval函数用法 PHP中eval()函数小技巧

eval 将值代入字符串之中。 语法: void eval(string code_str); 传回值: 无 函式种类: 数据处理 内容说明 本函式可将字符串之中的变量值代入,通常用在处...

php chr() ord()中文截取乱码问题解决方法

复制代码 代码如下:<?php $lenth = 19; $str = "怎么将新闻的很长的标题只显示前面一些字,后面用.....来代替?"; echo strlen($str)&...

php Smarty date_format [格式化时间日期]

Example 5-8. date_format[日期格式] index.php: 复制代码 代码如下: $smarty = new Smarty; $smarty->assign...

通达OA公共代码 php常用检测函数

check_type.php(使用类型检验函数) 复制代码 代码如下: <?php /*********************/ /* */ /* Version : 5.1.0...