You really shouldn’t rely on WP Cron if you’re using Datafeedr. Using the default WP Cron it will only run when visitors are accessing your site. Given that you’ve got all those Datafeedr product sets to update, you really want your CRON to be able to run overnight. Also, you get some easy access to cron history and cron errors (e.g. have them emailed to you).
So instead of using WP-Cron, follow the simple instructions below to set up a real cron job for your WordPress site. This will really help you if you’ve got large product sets to import or maintain on a daily basis.
Firstly, SSH onto your website. Your web hosts will provide you with SSH access. If you’re using shared hosting they may not provide this. (Why use shared hosting when Digital Ocean provide VPS setups for $5pcm?)
Now add your cron job. All you need to do is point a WGET command at your wp-cron.php file.
(Don’t have Datafeedr yet? Get the Datafeedr API – with that you can scale to MILLIONS of products on your store.)
Create the cron job
Create a cron job using the following command:
(it’ll ask you which editor to use – nano is easy to use – use arrow keys and then ctrl-x to exit and hit ‘Y’ to save your changes then ENTER to confirm where to save it)
Navigate to the bottom of the file and enter the following line – change YOURWEBSITE.COM to your own website URL.
*/1 * * * * wget -q -O – http://YOURWEBSITE.COM/wp-cron.php?doing_wp_cron
That will instruct the cron job to run wget against your wp-cron.php file every 1 minute. By using WGET rather than PHP-CLI you benefit from the anti-locking feature built into wp-cron.
Optionally disable wordpress cron
Finally, add the following line to wp-config.php (near the top is fine). This is optional because wp-cron.php has anti-blocking built into it, so even if you have wp-cron.php called from your cron every minute AND WordPress is calling wp-cron.php then everything will continue to operate. You’ll benefit from the fact that you have a regularly running cron which doesn’t rely on visitors to your site.
If you wish to monitor your cron job or have a look at its recent behaviour, run the following command in your shell:
grep CRON /var/log/syslog
Latest posts by Dave Hilditch (see all)
- My WordPress performance plugins and server stack have moved - July 31, 2016
- Price Comparison Pro 1.2 Released - July 5, 2016
- How to run backups on huge WordPress websites without your website being brought offline - February 4, 2016