I have a caching function and got HTML files.
Problem is I want to include my file into my page.
Example :
<h2>Before</h2>
<?php
cache('start');
// content....
cache('end');
?>
<footer>After</footer>
So my cache's function is so simple like...
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();}
}
Problem is ...
include($cachefile);
exit;
It's stop rendering after included. I tried to remove exit
so I got 2 multiple contents.
Any ?