Home >Backend Development >PHP Tutorial >Simple and practical php caching function_PHP tutorial

Simple and practical php caching function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:36:24882browse

/**
* @Description: File cache output
* @Parameter: $cachefile => cache file (absolute path)
* @Parameter: $pertime => Cache output interval
* @ Parameter: $sql => sql statement
* @Parameter: $templatefile => Template file name (absolute path)
**/
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;
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508228.htmlTechArticle/** * @Description: File cache output* @Parameter: $cachefile = cache file (absolute path) * @Parameter: $pertime = interval time for cached output* @Parameter: $sql = sql statement* @Parameter: $templa...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn