Building an HTML Cache of your Database Driven Site

Setting up a Cron Job

Depending on how frequently your content is updated you may want to only run the caching system when it needs an update, ie manually. However if your content is frequently updated you might want to run this nightly or even hourly. To do so you'll want to setup a cron job.

Cron is a system on unix & linux machines that runs programs at certain time intervals. Some control panels allow you to set cron jobs up from within them, for those that don't though you will need SSH access to your server. Once logged in you'll want to enter the following command:

crontab -e

Then in a simple text file you'll enter the following:

10 1 * * * php /full/path/to/your/cache/system.php

The first number is the minute number (0-59), the second number is the hour number (0-23), the third is a the day of month (1-31) number, the fourth is the month number (1-12) the fifth is the day of week number (0-6). Use an asterisk as a wildcard. So the above code will run every day at 1:10 AM. If you wanted to run at 1:10 AM every Sunday you'd use:

10 1 * * 0 php /full/path/to/your/cache/system.php

Other Considerations

Switching from full PHP to static HTML is a tremendous saver for server resources, however you're losing the ability to do calculations and any kind of database insert statement based off user page views. For instance you could never do this for an ecommerce site or any site that needs to track visitor sessions. You also will lose the ability to run any PHP based tracking software.

There is a compromise that will work for some functions. If you absolutely need PHP for tracking or for ad rotation you can do it out of an iframe in the static HTML file. You could also use this system to write PHP files bereft of all but the small amount of code you need. The resource savings will not be as much as if you went to straight HTML, but by caching most of the PHP you will still be saving quite a bit.

Further Reading