Set up WordPress cron to run via server cron in cPanel, Cloudways and RunCloud
By default the WordPress tasks that have been set up to run with wp-cron.php only run when a WordPress page is visited by a user, if the site has low traffic then tasks make take a while to action, if the site is high traffic and has caching then this can also cause reliability issues, instead you can manually set up the cron tasks to run at a timed schedules instead.
Disable default WordPress wp-cron.php
Disable the default WordPress cron behaviour by adding a PHP constant to the wp-config.php file.
define('DISABLE_WP_CRON', true);
Now WordPress wp-cron won’t run in its default way, but you’ll have to now set up a manual server cron job on your hosting platform, below are 3 ways with Cloudways, cPanel and RunCloud..
Set up WordPress cron with Cloudways
Go to Application Management > Cron Job Management > Add New Cron Job
In the next screen add the location path of the wp-cron.php file and how often you want to run it, my example runs it every 30 mins, for sites with a loy of functionality you are best to set this to every 5 mins
(By setting the cron job up with the Basic tab in Cloudways, the task is automatically run by PHP, whereas in cPanel you need to explicitly add the PHP path. If you swap to the Advanced tab in Cloudways you’ll see the PHP path in full)
Set up WordPress cron with cPanel
In cPanel search for Cron and add a new one.
Make sure add the correct path to wp-cron.php
Then set a schedule, this example sets a 5min interval, you also have an option of an email alert if you want to alert any errors.
Set up WordPress cron with RunCloud
You can set up cron jobs easily in the RunCloud panel, they have a cron section for each server that is configured.
Above I have a high traffic site which I just need wp-cron run every 5mins – typically the it would be like very 5-15mins, some hosts have a minimum time of 15 mins. With RunCloud leave the Vendor Binary as blank.
Viewing and Running wp-cron.php with WP Crontrol plugin
WP Crontrol plugin can show you a list of tasks or events that are scheduled to run, you can edit, delete or run the tasks now, this is a good way to troubleshoot events that are stuck or past the time.
Viewing and Running wp-cron.php with WP CLI
With WP CLI installed you can list all events.
wp cron event list
You should see output like…
+-------------------------------------------+---------------------+-----------------------+---------------+ | hook | next_run_gmt | next_run_relative | recurrence | +-------------------------------------------+---------------------+-----------------------+---------------+ | jetpack_v2_heartbeat | 2019-10-17 03:56:45 | now | 1 day | | action_scheduler_run_queue | 2019-10-17 04:00:08 | now | 1 minute | | jetpack_sync_cron | 2019-10-17 04:01:42 | now | 5 minutes | | jetpack_sync_full_cron | 2019-10-17 04:01:42 | now | 5 minutes | | prli_cleanup_visitor_locks_worker | 2019-10-17 04:16:11 | now | 1 hour | | jetpack_clean_nonces | 2019-10-17 04:23:01 | now | 1 hour | | wp_privacy_delete_old_export_files | 2019-10-17 04:39:57 | now | 1 hour |
The tasks or hook names are on the left and the other columns list their run time and frequency
To run all events due now…
wp cron event run --due-now
To run a specific event now, choose the hook name…
wp cron event run jetpack_v2_heartbeat
Running wp-cron when site is fully cached
If you have a fully cached site and your event hooks are not running, try this cron command instead…
wget -q -O - https://examplesite.com/wp-cron.php?doing_wp_cron
I have experienced a site cached with Swift Performance Lite that was not running the scheduled cron tasks, the cron command above fixed it which I found referenced at Siteground hosting.
Remote crons
You can also use remote cron service instead to schedule tasks, one such is https://cron-job.org which is free, there are others and paid solutions too.
That’s it, with WP CLI it makes it easy to troubleshoot and see what is going on and generally setting the cron to run on a set basis makes for better cron allround.