Simple Page Caching


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.