我有一个缓存功能并获得了HTML文件。包含一个文件并替换它
问题是我想将我的文件加入到我的页面。
例子:
<h2>Before</h2>
<?php
cache('start');
// content....
cache('end');
?>
<footer>After</footer>
所以我的缓存的功能是如此简单的像......
function cache($a,$min=null) {
global $cachefile;
$cache_path = "/cached/";
$file_name = basename(rtrim($_SERVER["REQUEST_URI"],'/'));
$file_path = 'http'.(empty($_SERVER['HTTPS'])?'':'s').'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$cachefile = $cache_path.sha1($file_path).'.cache';
if($a == 'start'){
$lifetime = $min * 60;
if(file_exists($cachefile)&&time()-$lifetime<filemtime($cachefile)){
include($cachefile);
exit;
}
ob_start();
}
if($a == 'end'){$fp=fopen($cachefile,'w');fwrite($fp,ob_get_contents());fclose($fp);ob_end_flush();}
}
问题是...
include($cachefile);
exit;
它停止渲染包括在内。我试图删除exit
,所以我得到2多个内容。
有没有?
只是把你的函数'cache'在全球utils的文件,包括一次 – Adidi 2013-04-26 12:11:01
你得到任何错误或页面空白 – 2013-04-26 12:18:46
没有任何错误,我只想替换'cache('start');'和'cache('stop')之间的所有内容;'@NanheKumar – l2aelba 2013-04-26 12:22:08