Server Side Caching in PHP - Optimize caching

<?phpinclude(top-cache.php);/* Your regular PHP code goes here */include(bottom-cache.php);?>

top-cache.php

$cachefile = cache/home.html;$cachetime = 60; /* Time in seconds to keep a page cached */

if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { readfile($cachefile); exit;}ob_start(); /*Start the output buffer*/

bottom-cache.php

$fp = fopen($cachefile, 'w');fwrite($fp, ob_get_contents()); /* save the contents of output buffer to the file */fclose($fp);ob_end_flush(); /* Send the output to the browser */

Measure the speed of code written in php.

$startTime = microtime(true);echo 'Time: ' . number_format(( microtime(true) - $startTime), 5) . ' Seconds';