In trying to cut down on database usage I have started using a limited cache function in and around the front page. Using the PHP Output Buffer to catch the screen output and save it. As found here. Though using an if-else instead of the blunt exit which obviously screws up the site since I’m not caching the entire page but rather portions of it. Hopefully this will take some stress off of the mysql database.
[php]$cachefile = “/blah/cache/”.$reqfilename.”.html”;
$cachetime = 30 * 60; // 30 minutes
if (file_exists($cachefile) && (time() – $cachetime < filemtime($cachefile)))
{
include($cachefile);
} else {
ob_start();
//
// run external code or html code here
//
$fp = fopen($cachefile, ‘w’);
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_flush();
}[/php]Pretty nifty if you ask me.
Contact
Lifestream




