Event Scheduling and wp-cron

WordPress has a built in system for running scheduled events called the WordPress Cron, or wp-cron for short. This allows PHP functions to run at a particular time, at a particular frequency.


About wp-cron

The default WordPress cron functionality, called wp-cron, checks on each page load for scheduled tasks that are due to run. This means wp-cron is not a true server cron and fires solely based on traffic to the website.

To leverage default wp-cron functionality there are a few options:

  1. Within a page or a post within WordPress, set a publish date using WordPress’ Schedule Event feature.
image00
  1. Add a new cron event by using the wp_schedule_event function within the theme or plugin code.
  2. Schedule an event using WP CLI.

While WordPress does have some scheduling capabilities, many website managers prefer a more comprehensive toolset for scheduling events. WP Crontrol and Advanced Cron Manager are two examples of cron plugins that some of our customers have used successfully.

Technical Information

  • After creation, a cron event is added to the wp_options table.
  • Manage crons with a plugin easily, such as WP Crontrol or Advanced Cron Manager.
  • If using WP CLI, view crons by running wp cron event list and find a full list of cron commands here.
  • WordPress triggers wp-cron.php when any page of the website is visited. This process queries the list of wp-crons for any that are “due now” and executes them.

Missed Cron

WordPress will check for scheduled events on every page visit, rather than every second (like a true server cron). This generally works fine, but it can cause problems in two ways:

  • If a website doesn’t get much traffic, crons will not be triggered to run very often. Crons will only run when someone visits the website. This is the most common reason that a website’s event misses its scheduled time.
  • If a website gets a lot of traffic, the process to check for crons will be triggered very frequently. This causes the server to work harder than it really needs to and can cause slowness, timeouts, and other performance issues on the website.

WP Engine Alternate Cron

Missed crons and crons that run too frequently can both be resolved by enabling the WP Engine Alternate Cron. This alternate cron is a service on the server itself and checks for “due now” crons every minute by curling wp-cron.php, rather than running cron processes based on traffic flow.

The alternate cron can be used to mimic a true server cron, even though WP Engine does not technically support true server crons. Alternate cron runs at a consistent minute interval and can be used to ensure processes run at their required time.

Alternate cron can be enabled within your User Portal by following these steps:

  1. From the Sites page, select the Environment you wish to enable Alternate Cron on
  2. Click Utilities in the secondary menu on the left (You may have to expand the Advanced dropdown section)
  3. Click the Alternate cron toggle switch to turn it on
Screenshot of and environment's Utilities page in the WP Engine User Portal showing where to enable Alt Cron

Alternate cron requires wp_cron be set to false, which means that the WordPress default cron must be disabled. This may conflict with other custom functionality on the website, so testing may be necessary after initially enabling the feature. To disable WordPress cron, alternate cron sets the following define in the website’s wp-config.php file and confirms this define is set daily through server processes.

define( 'DISABLE_WP_CRON', true );

Simply adding disabling wp cron within the environment’s config file will not enable WP Engine alternate cron on its own. Be sure to follow the steps above to properly enable alternate cron for the environment.

Websites using WP Engine’s Password Protection will work correctly with our alternate cron. However, alternate cron does not work for websites that are utilizing other forms of custom password protection (basic auth, etc) because it must remain publicly accessible.


Troubleshooting

If enabling alternate cron doesn’t work for the website, or the website needs wp_cron to read as enabled, there are some additional troubleshooting steps to help determine the issue with cron events.

First determine if the crons are failing, or if the updates simply aren’t showing. If the cron process is functioning but updates aren’t displaying, there may be a cache issue and not a cron issue.

If crons are failing to run:

  1. Locate the Site Access Logs
  2. Search for: wp-cron.php
  3. If the website has crons running, there will be entries like the following:
    • 200 response code denotes the cron is working correctly.
    • 502 response code denotes a timeout.
      • To correct, optimize the cron process to complete under 60 seconds.

If you’ve confirmed wp-cron is not working on the website, but are still unsure, we highly recommend reaching out to Support at this point for further guidance.

Advanced Troubleshooting

  • Confirm the domain added in the User Portal for this website matches what is mapped within WordPress.
  • If possible, use WP CLI to wp cron event list to see if crons are stuck or not.
    • Crons that are scheduled to next_run: now should be updating if cron is functioning as expected.
    • If crons are not updating, try running wp cron event run --due-now to see if the process gets hung up anywhere. Crons need to fire sequentially, if there’s an error with a previous cron, the following cron may not run.
  • Is the website password protected?
  • Check the website’s error logs.
    • It’s possible an error in the theme, plugin, or core code is causing issues with the PHP code in the cron.

NEXT STEP: Learn how to diagnose and troubleshoot a 502 error

Still need help? Contact support.

We offer support 24 hours a day, 7 days a week, 365 days a year. Log in to your account to get expert one-on-one help.

The best hosting for WordPress

See why more customers prefer WP Engine over the competition.