Blog, WordPress, Wp-Cron

WordPress: How to Change WP-Cron with Real Cron Job

Wp-Cron is responsible for running scheduled jobs such as scheduled posts and WP Super Cache preload. Whenever there's visitor, wp-cron checks jobs to run. However, a scheduled job may be missed if visitors are rare. On the other hand if not properly scheduled, cron may trigger many simultaneous processes that eat server resources.

The first issue I faced at that time was that I had six installation of WordPress at my domain, one in the main domain and five in sub-folders. The second issue was to decide time interval of the real cron job for each installation. The third one was impact of the changes to WP Super Cache preload.

To reduce server load I finally got rid of two sub-folders to be merged into the main domain. Elimination of Google Map plugin and replaced it with plain GPS data linked to Google Map and Waze links (for Andorid and iOS smartphone) also helps lighten server's work. As for setting the interval of cron job, I did it with trial and error.

In contrast to the WP-Cron that could not be controlled, real or Linux cron jobs can be controlled by user in order to ensure execution of a scheduled job. For sites with many visitors, Linux cron job may help reduce the probability that the site crashed by lowering bandwidth on the server, as it uses less server resources.

To Replace WP-Cron with Real Cron Job, follow steps shown below:

Deactivate wp-cron.php

  1. Login to cPanel. Open wp-config.php located at WordPress installation folder
  2. Copy following code and paste it somewhere after "define('AUTH_KEY' ..." or anywhere after <?php
    define('DISABLE_WP_CRON', true);
  3. Save, close wp-config.php

Create Linux / Real Cron Job

Follow steps listed below if you have only one WP installation, no subdomain, no subfolder.
  1. At cPanel, scroll down to "Advance" block and click "Cron Jobs" icon
  2. If you are using WP Super Cache preload with more than 100 posts, cron may be set every half an hour by choosing "Twice Per Hour(0,30 * * * *)" from drop down menu of "Common Settings "
    You may also choose every hour and select "Once Per Hour(0 * * * *)" from the menu.
    Preload stops after 100 posts and starts again on next cron, and hence the longer cron interval the longer preload will be completed.
    It is not recommended to set cron interval less than 15 minutes.
  3. On the "Command:" line, copy and paste following code:
    wget -q -O - http://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
    Replace "yoursite" with your site's address.
    Press "Add New Cron Job" button.

Staggering Interval for Linux Cron Jobs

If you have more than one WordPress installlation in a doman, than you need to stagger cron jobs so that they will not run at the same time that will suck server resources. Follow steps below:
  1. Divide 60 (minutes) with number of WP installation. If there are 4 then 60/4 = 15. This in the number of interval in minutes.
  2. For first WP installation use: 0 (zero) for Minute, * (star sign) for Hour, * for Day, * for Month and * for Weekday.
    On the "Command:" line:
    wget -q -O - http://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
    Press "Add New Cron Job"

  3. Fore the second WP installation, e.g. blog subfolder use: 15 * * * *
    On the "Command:" line copy paste code below:
    wget -q -O - http://yoursite.com/blog/wp-cron.php?doing_wp_cron >/dev/null 2>&1
    Press "Add New Cron Job"
  4. For the third WP installation, e.g en subfolder use: 30 * * * *
    On "Command:" line:
    wget -q -O - http://yoursite.com/en/wp-cron.php?doing_wp_cron >/dev/null 2>&1
    Press "Add New Cron Job"
  5. As for the fourth WP installation, e.g. shop subfolder use: 45 * * * *
    Pada "Command:"
    wget -q -O - http://yoursite.com/shop/wp-cron.php?doing_wp_cron >/dev/null 2>&1
    Press "Add New Cron Job"

With that each cron job runs every hour with 15 minutes interval to avoid overlap which will help to preserve server resources.


, seorang pejalan musiman dan penyuka sejarah. Penduduk Jakarta yang sedang tinggal di Cikarang Utara. Diperbarui: January 21, 2017.

Leave comments

Type it first, then click "Login ..." or "Posting".

« Newer©2021 FollowOlder »

Treat me for a cup of coffee, or just pray for those who make your life better.