更新了每天定时更新缓存页功能。
比如想要六点半更新,完全可以!
<?php
/******************
require(ECMS_PATH . 'd/timeCache.php');
*******************************************/
$strImg = <<<EOF
,,, ,|, ,,,
,||| ||' '||| ,,,|||,
||| ,||' ,,|||, ,|| '|||'''|||'
,||' ,|'||||' ,|||' ||',,, ,||'
,|||| ' || '' ,|||||| |||,,||
|' || || ,,|||'|| ||'|||'''||'
|| , || '||, '|'' |,,|' ||
|| || || '||| ,|||, ||
|| ||| || || ,||'' ||| ||
|| ' ,,,|| '' '' ,,,||
'' '||| '||||
''' ''
EOF;
//缓存存放目录
define('CACHE_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cacheFile');
//缓存时间 单位秒
define('CACHE_TIME', 86400);
//缓存文件后缀
define('CACHE_FIX','.php');
date_default_timezone_set("Asia/Shanghai");
$CacheName=md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) . CACHE_FIX; //缓存文件名
$CacheDir=CACHE_ROOT . DIRECTORY_SEPARATOR . substr($CacheName,0,1);
$CacheUrl=$CacheDir . DIRECTORY_SEPARATOR . $CacheName;
if(file_exists($CacheUrl) && time()-filemtime($CacheUrl)<CACHE_TIME && date('H:i', time()) > '06:30'){
echo gzuncompress(file_get_contents($CacheUrl));
exit;
}
elseif(!file_exists($CacheDir)){
if(!file_exists(CACHE_ROOT)){
mkdir(CACHE_ROOT,0777);
chmod(CACHE_ROOT,0777);
}
mkdir($CacheDir,0777);
chmod($CacheDir,0777);
}
function AutoCache($contents){
global $CacheUrl,$strImg;
$fp=fopen($CacheUrl,'wb');
$contents = "<!-- \r\n {$strImg} \r\n 俱往矣,数风流人物,还看今朝 本页面缓存时间 ".(date("Y-m-d H:i:s", time()))." \r\n-->\r\n".$contents;
fwrite($fp,gzcompress($contents));
fclose($fp);
chmod($CacheUrl,0777);
return $contents;
}
ob_start('AutoCache');
clearstatcache();
定期更新页面
<?php
/******************
require(ECMS_PATH . 'cache/cache.php');
*******************************************/
//缓存存放目录
define('CACHE_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cacheFile');
//缓存时间 单位秒
define('CACHE_TIME', 172800);
//缓存文件后缀
define('CACHE_FIX','.php');
date_default_timezone_set("Asia/Shanghai");
$CacheName=md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) . CACHE_FIX; //缓存文件名
$CacheDir=CACHE_ROOT . DIRECTORY_SEPARATOR . substr($CacheName,0,1);
$CacheUrl=$CacheDir . DIRECTORY_SEPARATOR . $CacheName;
if(file_exists($CacheUrl) && time()-filemtime($CacheUrl)<CACHE_TIME){
echo gzuncompress(file_get_contents($CacheUrl));
exit;
}
elseif(!file_exists($CacheDir)){
if(!file_exists(CACHE_ROOT)){
mkdir(CACHE_ROOT,0777);
chmod(CACHE_ROOT,0777);
}
mkdir($CacheDir,0777);
chmod($CacheDir,0777);
}
function AutoCache($contents){
global $CacheUrl;
$fp=fopen($CacheUrl,'wb');
$contents = "<!--缓存插件".(date("Y-m-d H:i:s", time()))."-->\r\n".$contents;
fwrite($fp,gzcompress($contents));
fclose($fp);
chmod($CacheUrl,0777);
return $contents;
}
ob_start('AutoCache');
clearstatcache();
长期永久缓存
<?php
/******************
require(ECMS_PATH . 'cache/content.php');
*******************************************/
//缓存存放目录
define('CACHE_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cacheFile');
//缓存文件后缀
define('CACHE_FIX','.php');
date_default_timezone_set("Asia/Shanghai");
$CacheName=md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) . CACHE_FIX; //缓存文件名
$CacheDir=CACHE_ROOT . DIRECTORY_SEPARATOR . substr($CacheName,0,1);
$CacheUrl=$CacheDir . DIRECTORY_SEPARATOR . $CacheName;
if(file_exists($CacheUrl)){
echo str_replace("{time181}",date("Y-m-d h:i:m",time()-1440),gzuncompress(file_get_contents($CacheUrl)));
exit;
}
elseif(!file_exists($CacheDir)){
if(!file_exists(CACHE_ROOT)){
mkdir(CACHE_ROOT,0777);
chmod(CACHE_ROOT,0777);
}
mkdir($CacheDir,0777);
chmod($CacheDir,0777);
}
function AutoCache($contents){
global $CacheUrl;
$fp=fopen($CacheUrl,'wb');
$contents = "<!--缓存插件 ".(date("Y-m-d H:i:s", time()))."-->\r\n".$contents;
fwrite($fp,gzcompress($contents));
fclose($fp);
chmod($CacheUrl,0777);
return str_replace("{time181}",date("Y-m-d h:i:m",time()-1440),$contents);
}
ob_start('AutoCache');
clearstatcache();
本文摘自网络,不代表短经典网立场 https://www.duanjingdian.com/667.html