07-18-2013, 08:36 AM | #1 |
Registered User
Join Date: Mar 2013
Posts: 246
|
Super simple page caching.
When your project isn’t based on a CMS or framework, it can be a good idea to implement a simple caching system on your pages. The following code snippet is very simple, but works well for small websites.
PHP Code: <?php // define the path and name of cached file $cachefile = 'cached-files/'.date('M-d-Y').'.php'; // define how long we want to keep the file in seconds. I set mine to 5 hours. $cachetime = 18000; // Check if the cached file is still fresh. If it is, serve it up and exit. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { include($cachefile); exit; } // if there is either no file OR the file to too old, render the page and capture the HTML. ob_start(); ?> <html> output all your html here. </html> <?php // We're done! Save the cached content to a file $fp = fopen($cachefile, 'w'); fwrite($fp, ob_get_contents()); fclose($fp); // finally send browser output ob_end_flush(); ?>
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
11-05-2013, 11:53 PM | #2 |
Registered User
Join Date: Sep 2013
Posts: 92
|
thanx for sharing.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Do redirected page backlinks & pr info count? | wryfhk22 | Search Engine Optimization | 7 | 08-23-2022 09:48 AM |
Secrete for seo | alina albert | Search Engine Optimization | 87 | 03-11-2018 05:47 AM |
Can I Boost a Page to Google First Page in a Week from 13.5 Million Competitors? | junwe | Search Engine Optimization | 5 | 01-06-2017 10:27 AM |
Enterprise standing front page optimization details small analysis | forgingmachine | 0 | 11-15-2012 07:17 PM | |
RSS Feed | rajivwebads | Search Engine Optimization | 12 | 08-31-2012 07:15 AM |