Subscribe via

Automatically Turn on WP-Cache During Traffic Storms

Thaya Kareeson


I am a semi-fan of WP-Cache. On the good side, it reduces strain on apache by staticising WordPress pages. On the bad side, it messes with my site statistics and makes development hard (I always forget that the page I’m working on is being cached). I like my statistics, but what if I suddenly get a traffic storm? If my site gets dugg, there is no time to worry about statistics. I would need all the help I can get to serve pages efficiently. This is why WP-Cache should be off by default and automatically turned on during traffic storms.

A lot of WordPress optimization techniques I use for this blog were taken from the awesome tutorials at TurbochargedCMS. One of the coolest technique on the tutorial was the WP-Cache on demand section. The tutorial gives complete instructions on how to set it up a monitoring system to automatically turn WP-Cache on if the server response time is too long.
The system is really just a couple of useful scripts and cron.

The first script (Bash shell script) is used to comment and uncomment the following line in the wp-config.php file, which effectively disables/enables WP-Cache:

define ('WP_CACHE', true);

The second script (written in Python) is used to check how long your website takes to load. If the load time takes longer than expected, then the python script calls the bash script to enable WP-Cache. The python script then goes to sleep for an hour. When it wakes back up, it will call the bash script again to turn WP-Cache off.

After the scripts are set up, all you have to do is cron the python script to run every minute and you are done. Now I’m pretty confident that my old machine can handle being dugg. The only bottleneck for me now is my ISP (SBC yuck).

Save and Share
StumbleUpon
Reddit

Currently experiencing problems with Intense Debate commenting system. Please make sure your browser's Javascript is enabled and try again later.