To keep your blog running smoothly, WordPress often needs to schedule tasks to run at certain times, or at some point in the future. Examples include scheduling posts for publication at a future date, generating backups and newsletters at regular intervals.
In order to make this happen, WordPress has an internal feature called wp-cron. In order to make WordPress easy to install, a nasty hack is used to execute wp-cron every time a visitor hits your site, or you do anything on the dashboard.
There are several problems with this:
It increases the load on your server, especially if you have a lot of visitors
It's erratic, especially if you have few visitors or use a caching plugin like W3-Total-Cache
- There's a bug that can cause it to execute multiple times in parallel, leading to annoying problems such as duplicate MailPress newsletters
It's a hack
Notice that problems occur both if you have too many visitors, and if you have too few. And you should be using a caching plugin. All this is bad news.
For these reasons, I recommend you disable background execution of wp-cron by WordPress, and set up a real cron job in you host's control panel to execute wp-cron at regular, predictable intervals. To do this, start by adding this to your wp-config.php:
/* Disable evil background wp-cron */ define('DISABLE_WP_CRON', true);
Then you need to create a real cron job to run wp-cron at regular intervals. On CPanel hosting services like HostGator, log in to your CPanel. Under the Advanced section at the bottom, click the icon labelled Cron jobs. Make sure the Cron email address is set correctly to your email address.
Add a new cron job, selecting Common Settings: Twice a day. If you know your blog needs finer scheduling then you can increase this to Once an hour say, but otherwise twice a day should be plenty.
Specify the command as:
/usr/bin/php -f /home/username/public_html/wp-cron.php >/dev/null
Replace username with your username. Initially you might want to leave off the
>/dev/null bit so you can see the output and check that it looks OK. I don't recommend redirecting the error output by adding
2>&1, because if there are errors you want to know about them.
If you're on IX Web Hosting, note that Cron is under FTP -> FTP Manager -> FTP User -> Crontab and you'll probably have to include a path to the PHP config file you use to increase the PHP memory_limit. So it'll look more like this all on one line:
/hsphere/shared/php5/bin/php -c /hsphere/local/home/username/domain.name/cgi-bin/php.ini -f /hsphere/local/home/username/domain.name/wp-cron.php >/dev/null
If you happen to have enabled WordPress's multisite feature, which is unlikely if you're just creating a personal or small-business blog for yourself, read disabling multisite wp-cron.
And you're done! We now return you to your regularly scheduled wp-cron task.
If you want to know more, here are some other articles I found helpful about disabling background wp-cron: