Simple page caching

I will give an example of a simple caching of PHP pages with an interval of 600 seconds (10 minutes).

Paste at the beginning of the code:

$modif=time()-@filemtime ("cache/$crc");
if ($modif<600)
include ("cache/$crc");
ob_start ();

The code for the page itself:


Paste at the end of the code:

$cache = ob_get_contents();
ob_end_clean ();
echo $cache;
$fp = @fopen ("cache/$crc", "w");
@fwrite ($fp, $cache);
@fclose ($fp);

We will also create the “cache” folder, after opening the page a cache will be written to it.

Leave a comment

Leave a Reply