Home Replacing WordPress wp-cron with a cron job
« Home »
Jul 25th, 2012 Comments Off on Replacing WordPress wp-cron with a cron job

Replacing WordPress wp-cron with a cron job

There is a build-in feature in WordPress for scheduling various events, which is called wp-cron. For some reason or other it seems to work very sporadically, and in my case for backup scheduling, most of the time it didn’t work at all, causing missed backups. So, I had to do something about it…

On servers running on a Linux machine there is another much more reliable option for scheduling tasks: Linux’s own cron. In the next tutorial I’m trying to explain the required steps to switch from wp-cron to a real cron. I’m assuming here that you have at least basic Linux/Unix skills.

1) First, edit wp-config.php and add the following line to disable WordPress built-in cron

define('DISABLE_WP_CRON', true);

2) Add a cron job using

crontab -e

In this example I want to do the backup to Dropbox (using BackWPup plugin) on Fridays at 18.00. For more information about the crontab syntax please see the various cron tutorials in the web.

* 18 * * 5 wget -O /dev/null http://yoursite.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1

Replace ‘yoursite.com’ with your website URL.

3) Test it

wget -O /dev/null http://yoursite.com/wp-cron.php?doing_wp_cron

If this works without error, all is well, and your new scheduling should be working. But if you get an error message like ‘403 Forbidden’, something is seriously wrong. This error caused me a lot of headscratching, but I finally found out that the BulletProof Security plugin was blocking wget as a User Agent. Consequently I needed to do the following alteration to the .htaccess file

- RewriteCond %{HTTP_USER_AGENT} (libwww-perl|wget|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC,OR]
+ RewriteCond %{HTTP_USER_AGENT} (libwww-perl|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC,OR]

In short, if you have any problems with the cron, please double- and triple-check your .htaccess settings!

Comments are closed.

Return to Top ▲Return to Top ▲