WP-Cron is an in-built feature of WordPress that’s used to run scheduled tasks, such as publishing posts, checking for updates, sending emails, and more.

When WP-Cron is executed, it checks a list of scheduled tasks to see what needs to be run. By default, WP-Cron is executed on every page load, and the wp-cron.php file is triggered by an HTTP request that WordPress sends to itself.

WP-Cron is useful for performing tasks that do not need to be run exactly at a specific time, but rather periodically, or occasionally. However, WP-Cron has some limitations and drawbacks.

WP-Cron may not run reliably if your site has low traffic, or has caching enabled. WP-Cron may also cause performance issues if you have too many tasks, or long-running tasks that slow down the page load. Therefore, it is recommended to disable WP-Cron and use the real system cron scheduler instead, which doesn’t rely on visitor traffic, and is much more predictable. 

Refer to our post on adding Cron jobs on RunCloud to learn how to do this.

Investigating WP-cron Jobs via WordPress CLI

WP-CLI is a command line tool that allows you to manage WordPress sites from the terminal. You can use WP-CLI to perform various tasks, such as creating posts, managing users, plugins, themes, and more. One of the features of WP-CLI is the ability to test, run, and delete WP-Cron events.

By using WP Cron CLI, you can get a better understanding of the inner workings of WordPress. You can use WP Cron CLI to do the following tasks.

Test the WP-Cron Spawning System

You can run the wp cron test command to test the WP-Cron spawning system and report back its status. It will tell you if WP-Cron is working as expected or if there are any errors or warnings.

List all the Scheduled WP-Cron Events

You can execute the wp cron event list command to list all the scheduled WP-Cron events and their details in a table format. You can use various options to filter, sort, or format the output.

Run a Specific WP-Cron Event Immediately

The wp cron event run <hook> command will run a specific WP-Cron event immediately, regardless of its schedule.

Run All Hooks

You can use the --all flag to run all the events.

In the above example, we can see that all the cron hooks were executed regardless of their schedule.

Run Hooks Due Past Their Schedule

You can include the --due-now flag to execute only the events that are due right now.

In the above example, we can see that only the events that were due now were executed when we ran the command.

You can find more details and examples of using WP Cron CLI in the documentation. Just run the wp cron --help command to view all the available options.