I'm trying to tidy up my code by getting to grips with OOP. I know that this isnt really OOP, but I want to put a cache system into a function.
The bit in comments is basically the bit that I want to put into a function. As you can see its fairly rudimentary but basically I dont know how to get what 'include' produces into the output buffer because, of course, its not actually outputting anything. I thought something like fopen() but its all PHP scripts in the include so taht wont work
Anyway, this is what I have:
$cachefile = 'cache/cache_blogphotofeed.html';
$include = 'feeds/blogphoto_feed.php';
$table = 'our_photos';
if (file_exists($cachefile)) {
if (is_outdated($cachefile, $table, $dbc)) {
// This bit
ob_start();
include($include);
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp); // close the file
ob_end_flush();[/b]
// To this bit
} else {
include($cachefile);
}
} else {
ob_start();
include($include);
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp); // close the file
ob_end_flush();
}
The function is_outdated simply checks if the database table has been modified more recently than the cache file
Any suggestions at all?