Have you ever noticed that your scheduled posts in WordPress are missing? Though WordPress has its own cron feature that dictates the scheduling of your blog's posts and events, WP-cron is not a literal cron job.
Real Cron Job vs. WP-Cron
Real cron jobs can be controlled by the user, making certain that the items constrained by schedule are run appropriately. Also, for a high-traffic WordPress site, a real cron job can assist with reducing the chances of downtime by lowering the bandwidth on the server, thus using less server resources.
WP-cron is a virtual cron that only works when the page is loaded. WP-cron is first loaded by WordPress when a page is requested on the front or backend of a site at which point WP-cron displays the necessary page to the site visitor. Though convenient, it is known to fail for a variety of reasons, including but not limited to the following:
- Conflict of plugins
- DNS-related issues
- WordPress bugs
- Use of caching plugins
- Large server load
Replace WP-Cron with a Real Cron Job
The best way optimize the efficiency of your WordPress cron jobs is to disable WP-cron and set up a normal cron job through cPanel which will run every hour.
1. Disable wp-cron.php
You can disable WP-cron by modifying the wp-config.php (located in the folder where WordPress is installed). Open the wp-config.php file and add the following line to the top of the page:
2. Set Up a Real Cron
To set up a real cron job:
- Log into your cPanel.
- In the Advanced section, click Cron jobs.
- Under Add New Cron Job, select the time interval. HostGator recommends that you do not set the interval lower than 15 minutes.
- Set the cron command to the following, replacing yourwebsite.com with your actual domain name:
wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1The above command tells the Linux server to run wp-cron via wget, which will trigger the wp-cron.php script to do it's job on your schedule instead of on each page view. This will lessen the amount of processes on the server.
- Click Add New Cron Job to set the cron.
In order to test out the new cron, simply wait for the elapsed time period for the cron to run. In the event that the cron does not run, please review the steps listed above to ensure that you have completed all steps correctly.