Posted By

iTony on 03/04/09


Tagged

php cache


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

jamesming
luman
pezland
nkrstevski
BrianCoyDesign


Simple Page Caching


 / Published in: PHP
 

URL: http://papearmashup.com/caching-dynamic-php-pages-easily

  1. $cacheFile = 'cache/index-cached.html';
  2. $cacheTime = 4 * 60;
  3. // Serve the cached file if it is older than $cacheTime
  4. if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) {
  5. include($cacheFile);
  6. }
  7. // Start the output buffer
  8.  
  9. /* Heres where you put your page content */
  10.  
  11. // Cache the contents to a file
  12. $cached = fopen($cacheFile, 'w');
  13. fwrite($cached, ob_get_contents());
  14. fclose($cached);
  15. ob_end_flush(); // Send the output to the browser

Report this snippet  

You need to login to post a comment.