So I implemented the code from the examples of the link I mentioned in my first post and created this:
<?php
$reqfilename = basename($_SERVER['PHP_SELF']);
$cachefile = $_SERVER['DOCUMENT_ROOT'].'/cache_chaindlk/'.basename($_SERVER['PHP_SELF']).'-'.$_SERVER['QUERY_STRING'].'.html';
//$cachefile = $_SERVER['DOCUMENT_ROOT'].'/cache_chaindlk/'.$reqfilename.'.html';
// Serve from the cache if it is the same age or younger than the last
// modification time of the included file (includes/$reqfilename)
if (file_exists($cachefile) && ( filemtime($reqfilename) < filemtime($cachefile)) ) {
include($cachefile);
echo "<!-- Cached ".date('H:i', filemtime($cachefile))." -->";
exit;
}
// start the output buffer
ob_start();
?>
code here;
<?php
// open the cache file for writing
$fp = fopen($cachefile, 'w');
// save the contents of output buffer to the file
fwrite($fp, ob_get_contents());
// close the file
fclose($fp);
// Send the output to the browser
ob_end_flush();
?>
My site is basically all dynamically created, all the content is pulled from the database to make up a page (which is while I modified the code in a way that the string query is part of the cached file name).
The thing I am confused about is this: isn't the condition filemtime($reqfilename) < filemtime($cachefile) always true??? I mean, if filemtime checks for the modification time of a file isn't a file that is created dynamically always 'younger' than the cached file? did I just create something that makes my website slower instead of faster because it just creates a copy of everything everytime I call a file?