Advertisement
Drakia

Untitled

Sep 25th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.     // Settings
  3.     $cachedir = './cache/'; // Directory to cache files in (keep outside web root)
  4.     $cachetime = 7200; // Seconds to cache files for
  5.     $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  6.  
  7.     // Script
  8.     $page = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Requested page
  9.     $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  10.  
  11.     $cachefile_created = (@file_exists($cachefile)) ? @filemtime($cachefile) : 0;
  12.     @clearstatcache();
  13.  
  14.     // Show file from cache if still valid
  15.     if (time() - $cachetime < $cachefile_created) {
  16.         //ob_start('ob_gzhandler');
  17.         @readfile($cachefile);
  18.         //ob_end_flush();
  19. ?>
  20. <div class="footer">Page took <?=round((utime() - $stime)*1000, 2);?>ms to load</div>
  21. </body>
  22. </html>
  23. <?
  24.         exit();
  25.     }
  26.  
  27.     // If we're still here, we need to generate a cache file
  28.     ob_start();
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement