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.
Linux cron job vs. WP-cron
The user can control Linux cron jobs, ensuring that the items constrained by the schedule are run appropriately. Also, for a high-traffic WordPress site, a Linux cron job can reduce the chances of downtime by lowering the bandwidth on the server, thus using fewer 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 site’s front or back end. Though convenient, it is known to fail for a variety of reasons:
• Conflict of plugins
• DNS-related issues
• WordPress bugs
• Use of caching plugins
• Large server load
How to Replace WP-cron With a Linux Cron Job
The best way to 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.
If you have multiple WordPress sites, you will need to stagger your cron jobs so they will not run simultaneously. This could potentially cause your site to become restricted.
Step 1: Disable wp-cron.php
You can disable WP-cron by modifying the wp-config.php file, which is located in your WordPress site’s document root.
1. Open the wp-config.php file.
2. Add a new line after <?php.
3. Add the following code on the new line:
define('DISABLE_WP_CRON', true);
Step 2: Set up Linux cron
You need to have a working knowledge of Linux commands before you can use cron jobs effectively.
1. Log in to your cPanel from Twilight I.T.
2. In the Advanced section, click Cron jobs.
3. Under Add New Cron Job, select the time interval. Do not set the interval lower than 15 minutes.
4. 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>&1
5. Click Add New Cron Job to set the cron.
Staggering Multiple WordPress Cron Jobs
Creating cron jobs for multiple WordPress cron without custom configuration can cause them all to fire at the same time. Having multiple cron jobs run simultaneously can cause your CPU usage to increase, negating the benefit of using Linux cron jobs.
To stagger your cron jobs:
1. Divide 60 by the number of WordPress installations you have. If you have more than 60, use the number 1.
2. When creating your WordPress cron jobs, use 0 for minutes for your first cron job.
3. For each cron job after the first one, add the number you got in Step 1.
Note: If you have more than 60 WordPress sites, after you reach 59, you will need to start at 0 again. If you experience CPU issues with this many WordPress sites running cron jobs this frequently, you may wish to consider migrating some of your sites to a second account.