Posted By

iTony on 03/04/09


Tagged

php cache


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

luman
pezland
Keef
nkrstevski
wirenaught


Cache Page Script


 / Published in: PHP
 

URL: http://paste.org/5666

  1. if (isset($useCache) && $useCache==1){
  2. if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']!="/"){
  3. $cacheName=str_replace('/','-',$_SERVER['REQUEST_URI']);
  4. $cacheName = substr($cacheName,1);
  5. }else{
  6. $cacheName='site-index.html';
  7. }
  8.  
  9. $cacheFile = "cache/{$cacheName}";
  10.  
  11. if(!isset($cacheTime)){
  12. $cacheTime = 4 * 60;
  13. }
  14.  
  15. if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) {
  16. include($cacheFile);
  17. }
  18.  
  19. }
  20.  
  21.  
  22. /************** Body of site **************/
  23.  
  24.  
  25. if (isset($useCache) && $useCache==1){ // Firstly we check, is caching enabled for this page, if yes do your best my script:)
  26. $cached = fopen($cacheFile, 'w');
  27. fwrite($cached, ob_get_contents());
  28. fclose($cached);
  29. ob_end_flush(); // Send the output to the browser
  30. }

Report this snippet  

You need to login to post a comment.