Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Settings
- $cachedir = './cache/'; // Directory to cache files in (keep outside web root)
- $cachetime = 7200; // Seconds to cache files for
- $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
- // Script
- $page = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Requested page
- $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
- $cachefile_created = (@file_exists($cachefile)) ? @filemtime($cachefile) : 0;
- @clearstatcache();
- // Show file from cache if still valid
- if (time() - $cachetime < $cachefile_created) {
- //ob_start('ob_gzhandler');
- @readfile($cachefile);
- //ob_end_flush();
- ?>
- <div class="footer">Page took <?=round((utime() - $stime)*1000, 2);?>ms to load</div>
- </body>
- </html>
- <?
- exit();
- }
- // If we're still here, we need to generate a cache file
- ob_start();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement