Posted By

silverius on 06/10/10


Tagged

php html cache


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

BrianCoyDesign
gecube


PHP cache Files


 / Published in: PHP
 

  1. $cachefile = 'cache.html';
  2. $cachetime = 4 * 60;
  3. // Serve from the cache if it is younger than $cachetime
  4. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
  5. include($cachefile);
  6. echo "<!-- Cached copy, generated ".date('H:i', filemtime($cachefile))." -->\n";
  7. }
  8. ob_start(); // Start the output buffer
  9.  
  10. /* Heres where you put your page content */
  11.  
  12. // Cache the contents to a file
  13. $cached = fopen($cacheFile, 'w');
  14. fwrite($cached, ob_get_contents());
  15. fclose($cached);
  16. ob_end_flush(); // Send the output to the browser

Report this snippet  

You need to login to post a comment.