Using the WordPress Cron (WP-Cron) Utility, this guide will cover managing WP-Cron Events using various WordPress Command Line Interface (WP-CLI) commands.
Overview of Managing WordPress Cron (WP-Cron) Events with the WordPress Command Line Interface (WP-CLI)
How Do You See WordPress Cron (WP-Cron) Events in WordPress?
Once on the WordPress Dashboard, click Tools > Cron Events. You will see a list all of the WP-Cron Events occurring on your WordPress website on multiple rows. Each WP-Cron Event is shown on its own row, with each one having a Delete option available.
How is a WordPress Cron (WP-Cron) Event Triggered?
WordPress Cron (WP-Cron) works by checking, at the time every page is loaded for the site, a list of scheduled tasks to see which of them needs to be run. Any WP-Cron Event due to run will be called during that page-loading event.
Please note that WP-Cron functionality does not run constantly as the System Cron functionality does. WP-Cron functionality is only triggered in conjunction with page-loading events.
Understanding Unix/Linux System Cron & Unix/Linux System Cron Jobs
The term "cron" refers to a system of commands that follow a schedule or run at regular intervals. For example, web servers generally use Cron (also known as System Cron) to manage server maintenance and to schedule tasks. Please be aware that these type of Cron Jobs are managed and run at the Unix/Linux operating system level, and thus are considered System Cron (Cron for short) and System Cron Jobs accordingly.
What are Cron (System Cron), Cron Jobs (System Cron Jobs) & Crontab?
Cron is a task scheduler that lets you execute a script or command automatically on a web server at a future date. It helps you automate repetitive processes. Cron is the Cron Job scheduler on Unix/Linux operating systems. For instance, you can use Cron to send emails at regular intervals automatically. Crontab (derived from Cron Table) is a file which contains the schedule of Cron Job entries to be run and at specified times.
Understanding the WordPress Cron (WP-Cron) Utility
WordPress has its own WordPress Cron (WP-Cron) system and corresponding WP-Cron Events you can use to schedule tasks. This guide will show you how to manage WP-Cron Events using various WordPress Command Line Interface (WP-CLI) commands.
What is WordPress Cron (WP-Cron)?
You can schedule tasks a minute to a year in advance using the WordPress Cron Utility called WP-Cron. Here are some scheduled tasks WordPress performs using WP-Cron:
Checking for WordPress core updates
Checking for plugin and theme updates
Cleaning up spam
Publishing a scheduled post
Many WordPress plugins also rely on WP-Cron to manage scheduled tasks — such as creating automatic backups, clearing the cache, etc. Each task is a WP-Cron Event.
Using the WordPress Command Line Interface (WP-CLI)
WP-CLI is the command-line interface for WordPress that lets you update plugins, configure multisite installations, and do more using commands. You can work on your website without opening a web browser or the WP-Admin Dashboard.
The WordPress Command Line Interface (WP-CLI) is preinstalled on all the Nexcess Managed WordPress hosting plans. You will need SSH credentials to get into the server and use WP-CLI.
If you are on an operating system like Linux or Mac, you can use the built-in SSH terminal. In contrast, Windows users can use PuTTY to access the server.
You can also create and modify WordPress scheduled tasks (WP-Cron) through the Nexcess Client Portal.
Managing WordPress Cron (WP-Cron) Events with Command Line Interface (WP-CLI)
Here are the WP-Cron commands you can use to schedule new tasks or manage the scheduled tasks.
wp cron event list
This command lists all WP-Cron Events scheduled to run on your WordPress website:
Listing Scheduled WordPress Cron (WP-Cron) Events with WP-CLI in the JSON (JavaScript Object Notation) Format
To obtain a list of the scheduled WP-Cron Events in JSON, add --fields=hook,next_run --format=json after the wp cron event list command:
If you manage a multisite, you will need to define a site URL as follows to list the scheduled tasks:
wp cron event run
This command executes the tasks associated with the given hook.
Running All Due WordPress Cron (WP-Cron) Events with WP-CLI
You can use the following WP-CLI command to execute all currently due WP-Cron Events:
Running a Scheduled WordPress (WP-Cron) Events Manually with WP-CLI
You might have to run a WP-Cron Event manually to see if things are working correctly or to troubleshoot certain things. The following command would help you achieve this:
Here is an example of running a scheduled WP-Cron Event manually:
To run all WordPress scheduled events manually, whether they are due or not, you can use the following WP-CLI command:
wp cron event schedule
This command lets you add your WP-Cron Events to your WordPress site. You can configure the WP-Cron event to run hourly, daily, or once a week. You can also set it up as a non-repeating event.
As you add your WP-Cron Events, they will appear in the events list.
Scheduling a Custom WordPress (WP-Cron) Event for a Specific Date/Time with WP-CLI
Use the following command to schedule a custom WP-Cron Event. The event will be triggered the next time the WP-Cron Utility runs:
Scheduling a Custom Cron Event for a Specific Date/Time
By adding additional parameters like the date and time, you can schedule Cron Events to run at a specific time. In the following example, a new event called “cron_test” is scheduled to run in one hour:
Here are other examples of scheduling a task to run at different times of the day:
>> Run the Event on a Specific Date
>> Run the Event in 1 Week
>> Run the Event Next Wednesday
Schedule Recurring Cron Events
To schedule recurring WP-Cron Events, you need to add a parameter specifying how frequently the event should occur. For instance, you can set a WP-Cron Event to run hourly, daily, weekly, monthly, or even yearly.
This example uses the WP-CLI command to instruct WordPress to run ‘cron_test’ now and rerun once per day:
The default intervals provided by WordPress are hourly, twicedaily, and daily. Check out the Code Reference at WordPress.org for more information.
wp cron event unschedule
This command lets you unschedule an event in WP-Cron:
wp cron event delete
You can also delete a scheduled event using WP-CLI. Run the following command along with the action hook name to delete an existing event:
The following example shows how you can delete all scheduled WP-Cron Events for a given hook, where ‘cron_test’ is the hook here in this example:
WordPress Cron (WP-Cron) & Performance
Most WordPress plugins depend on WP-Cron to schedule backups, site health checks, and cache management. Unfortunately, this can cause performance issues as all plugins try to access a single file.
WP-Cron is often triggered as a user visits your website. So for smaller websites with low traffic, you can rely on WP-Cron without performance issues. But for larger websites, WP-Cron becomes a performance bottleneck and slows down the whole website.
You can improve your website’s performance and reliability of the website’s scheduled tasks and reduce the server load by using an optimized WP-Cron Event Schedule. In Nexcess Managed WordPress Plans, the internal WP-Cron Utility is disabled by default to avoid performance issues.
Nevertheless, if you want to enable the WP-Cron Utility, open your wp-config.php file and change the value of 'true' to 'false' in this line:
However, we do not recommend enabling WP-Cron as it will drastically affect your site performance. If you are unsure how to handle this, please contact our support team by email or through your Client Portal.
wp cron test
If you're experiencing issues with scheduled tasks within WordPress, your WP-Cron configuration might be to blame. Run the following command on the WordPress root directory to ensure the WP-Cron system is working properly:
If you have your internal WP-Cron disabled as is the default setting on our Nexces WordPress plans, you will see the following message:
If that’s not the case, you should see this result:
Final Thoughts: Managing WordPress Cron (WP-Cron) Events with the WordPress Command Line Interface (WP-CLI)
Using this guide, you can schedule your tasks through WP-CLI. As a result, you can automate your recurring tasks and focus on your business instead of worrying about your website.
Do you have any questions?
Please get in touch with our support team by email or through your Client Portal. Or you can search the Nexcess Knowledge Base for your request.
Useful Links Related to the WordPress Cron (WP-Cron) Utility
- https://help.nexcess.net/client-portal/67-how-to-schedule-cron-jobs-in-nexcess-cloud
- https://help.nexcess.net/74113-siteworx/how-to-manage-cron-jobs
- https://help.nexcess.net/74152-nodeworx/how-to-administer-cron-jobs-in-nodeworx
- https://help.nexcess.net/74095-wordpress/wordpress-transients
- https://help.nexcess.net/74095-wordpress/wordpress-automatic-updates
Useful Links Related to WordPress Maintenance Mode
- https://developer.wordpress.org/cli/commands/maintenance-mode/
- https://developer.wordpress.org/cli/commands/maintenance-mode/activate/
- https://developer.wordpress.org/cli/commands/maintenance-mode/deactivate/
- https://developer.wordpress.org/cli/commands/maintenance-mode/is-active/
- https://developer.wordpress.org/cli/commands/maintenance-mode/status/
- https://github.com/wp-cli/maintenance-mode-command
- https://make.wordpress.org/cli/handbook/guides/common-issues/
-
https://developer.wordpress.org/cli/commands/cli/info/
Other Useful WordPress Links for Developers & Admins
- https://wp-cli.org/#using
- https://help.nexcess.net/74095-wordpress/locating-your-ssh-credentials-in-managed-wordpress-and-managed-woocommerce-hosting
- https://developer.wordpress.org/cli/commands/db/search/
- https://developer.wordpress.org/cli/commands/db/size/
- https://developer.wordpress.org/cli/commands/db/search/#options
- https://make.wordpress.org/cli/handbook/guides/common-issues/
- https://make.wordpress.org/cli/handbook/guides/troubleshooting/
- https://make.wordpress.org/cli/handbook/guides/identify-plugin-theme-conflict/
- https://make.wordpress.org/cli/handbook/contributions/bug-reports/
- https://developer.wordpress.org/cli/commands/cli/info/
- https://developer.wordpress.org/cli/commands/theme/list/
- https://developer.wordpress.org/cli/commands/theme/update/
- https://developer.wordpress.org/cli/commands/plugin/list/
- https://developer.wordpress.org/cli/commands/plugin/update/
- https://help.nexcess.net/74095-wordpress/wordpress-automatic-updates
- https://help.nexcess.net/74095-wordpress/how-to-enable-auto-updates-for-plugins-and-themes
About the Nexcess Portal
Starting with a new hosting partner can be overwhelming. For that exact reason, we have prepared a Nexcess Portal Guide to make each client’s introduction to our Nexcess Portal easier.
How to Become a Nexcess Portal Pro
You signed up for an account with Nexcess but now what do you do? New systems can be intimidating to learn, so we’ve put together this guide to help explain what is in the portal and where to find it.
Next Steps?
Read more about the Fully Managed WordPress Hosting and its benefits for your business.
Build Better Websites with Fully Managed WordPress Hosting
It’s hosting optimized for WordPress. That means a faster, more secure and scalable website. Smart monitoring tools are built-in to help you keep it that way.
It’s why WordPress Users Trust Nexcess Hosting.
We also have a variety of Nexcess support articles about WordPress, including how to get your site going with a number of different configuration options. These resources include a great article on setting this up for Migrating to Nexcess with managed WordPress and managed WooCommerce hosting.
24-Hour Assistance
If you need any assistance with the above-mentioned, don't hesitate to reach out. For 24-hour assistance any day of the year, Nexcess customers can contact our support team by email or through your Client Portal.
Useful YouTube > Nexcess Channel Links
- Nexcess on YouTube - Home
- Nexcess on YouTube - Welcome to Your Nexcess Portal
- Nexcess on YouTube - Featured Videos
- Nexcess on YouTube - All Videos
- Nexcess on YouTube - All Playlists
Resources for More Information
Need more help? The Applications, WooCommerce, and WordPress sections within the Nexcess Knowledge Base are important resources for those seeking additional knowledge. Or, check out our related articles below.
New Customers: Fully Managed Hosting Solutions
Not a Nexcess customer yet? Check out our fully managed hosting solutions. The option to chat with an expert is also available.
Related Articles
- Scope of Support
- Getting started with managed WordPress and WooCommerce hosting
-
Migrating to Nexcess with managed WordPress and managed WooCommerce hosting
- Going live with your site in Managed WordPress and Managed WooCommerce hosting
- WordPress Cleanup 101: 9 Easy Ways To Clean Up and Optimize Your WordPress Site
- How to configure the Nexcess CDN with WordPress and CDN Enabler
- The Nexcess Plugin Performance Monitor
- Viewing AWStats for Managed WordPress & WooCommerce