Using Linux Cron instead of WP CRON

There are some situations where the built-in WordPress cron system can be inefficient or problematic. If you have a Managed Server, you can easily disable the WordPress cron and use a Linux system cron instead.

The two primary benefits in doing this are:

  1. Performance: WordPress no longer has to run WP CRON on every page load
  2. Stability: WordPress crons only run when there's site activity. Linux crons run regardless of site activity.

Note that this technique only works for single WordPress installations. A difference approach is required for WordPress multisite.

Set up Linux Cron

Switching to Linux cron does require some familiarity with the Linux command line and editors such as Vim or Nano.

Login using SSH, as the user that owns the site you want to add a cronjob for, then open the crontab editor.

crontab -e

Add the cron command to the bottom of the crontab file, including a MAILTO parameter if you want the output emailed (useful for testing) If there is a ~/wp-cli.yml file created for the user, you can omit the --path.

MAILTO=me@website.nz
*/1 * * * * wp cron event run --due-now --path=apps/APPNAME/public

NOTE: if you are prompted to select a default editor, select Nano. You will only need to do this once.

Lastly, disable WP_CRON in your site's wp-config.php file:

define('DISABLE_WP_CRON', true);
Was this answer helpful? 0 Users Found This Useful (0 Votes)