php 緩存函數代碼
更新時間:2008年08月27日 12:55:37 作者:
簡單實用的緩存函數
復制代碼 代碼如下:
**
* @說明: 文件緩存輸出
* @參數: $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通過array_push()函數添加多個變量到數組末尾的方法
這篇文章主要介紹了php通過array_push()函數添加多個變量到數組末尾的方法,涉及php中array_push()函數操作數組的技巧,需要的朋友可以參考下2015-03-03
關于WordPress的SEO優(yōu)化相關的一些PHP頁面腳本技巧
這篇文章主要介紹了關于WordPress的SEO優(yōu)化相關的一些PHP頁面腳本技巧,包括區(qū)分顯示頁面標題和關鍵字等,需要的朋友可以參考下2015-12-12
PHP中類型轉換 ,常量,系統(tǒng)常量,魔術常量的詳解
這篇文章主要介紹了PHP中類型轉換 ,常量,系統(tǒng)常量,魔術常量的詳解的相關資料,希望通過本文能幫助到大家,讓大家掌握這部分內容,需要的朋友可以參考下2017-10-10

