Background

You should know that WordPress cron differs from real cron. This means that these scheduled tasks (also known as “cron jobs“) will only fire if there is a page load event in WordPress. These page load events usually come from your website visitors.

Therefore, if your site does not have visitors, no one triggers WordPress cron, and your WordPress scheduled tasks (including Prime Mover automatic backups) will never be executed. Or, if you have very few website visitors (common in very new sites), your scheduled tasks will execute late, and task execution will be prolonged.

This tutorial will illustrate a solution to this issue by using an external cron service.

Disable WP Cron

Before you can use external cron service – you need to disable WP CRON by adding this constant to your wp-config.php:

define( 'DISABLE_WP_CRON', true );

This tells WordPress to completely disable the native WordPress cron so you can delegate the cron calls to an external service. If you don’t add the above constant – WordPress cron will continue to fire scheduled tasks on page load by default. This is now redundant since you are now calling the cron script via an external service and adding that constant will improve the performance of your site so you are removing that redundant execution.

For more details on this topic – please checkout this official documentation from the WordPress cron handbook.

External cron service requisite

If you want to rely on an external cron service – your site must be publicly accessible via the Internet. This means that when an external script calls the WordPress cron script – it should not be blocked in any way.

This is not a problem if your site is hosted correctly (like in popular hosting platforms) and you are sure that your site has public DNS. But this is a problem if your site is private and only accessible to you or to selected visitors. Common examples include sites in the local environment (such as in your laptop) or sites within the Intranet network (such as your company network which is not exposed to the Internet).

If this is your case – you cannot enable and use external cron service. You should use the native system cron solution that comes from your hosting.

Enabling external cron service

External cron service works by pinging your website (just like having a website visitor) – but the difference is that this will only call the WordPress cron script (wp-cron.php). These calls are made on a scheduled basis. It could be every 5 minutes or every thirty minutes, so on and so forth.

In this tutorial – we will use cron-job.org which is a free service. Feel free to choose another similar paid service of your convenience.

  • Create an account in cron-job.org.
  • Create a cron job with a specific interval. Supposing you want to call the WordPress cron script every two minutes this will be the setting:
  • Finally, save it, and then every two minutes – this web service will call your site WordPress cron script. Make sure to provide the correct cron URL of your site.

Easy right? This free service includes statistics, logs, and history so you will know if your external cron calls are running fine or have some issues.

What to expect from this?

As long as the external cron service is running fine and not returning errors (as you can see in the logs) – then it should be guaranteed to run at your specified intervals. This will ensure that your scheduled tasks will be active and not always waiting in queue for a website visitor (just like it was originally or by default).

All your cron tasks should run according to schedule. These include all cron jobs added by all plugins like WooCommerce and the Prime Mover PRO automatic backup feature (if you are enabling it).

Multisite tips

If you are enabling automatic backup in a multisite and want to execute auto-backup for any of your sub-sites (including the main site) – make sure to use only the main site URL as part of your CRON URL when calling the script via external service. You don’t need to add all the URLs for your sub-site in the external cron service.

For example – suppose you have a multisite with the following sites (sub-folder configuration):

  • Main site URL: https://mydomain.tld/
  • 1st subsite: https://mydomain.tld/first-subsite/
  • 2nd subsite: https://mydomain.tld/second-subsite/

Then you should have the CRON URL based on your main site URL e.g.

https://mydomain.tld/wp-cron.php

Use that CRON URL to configure your external cron service (e.g. in cron-job.org). This will ensure that only the main site cron fires which is used by automatic backup functionality to analyze the firing sequence for all of your sub-site’s automatic backup schedules.

If you have a multisite with domain mapping functionality or configured using a subdomain – then always use only the main site CRON URL. For example (domain-mapped or subdomain multisite configuration):

  • Main site URL: https://mytestdomain.tld/
  • 1st subsite: https://anothergreatdomain.tld/
  • 2nd subsite: https://awesome-domain.tld/

Then you should have the CRON URL based on your main site URL e.g.

https://mytestdomain.tld/wp-cron.php

In any multisite – identifying the main site URL is easy regardless if you are using mapped domains/subdomains or using folder structure. Just log in as network administrator and go to Network admin -> Sites. WordPress labels your main site with “–Main” just like in the screenshot below:

Was this article helpful?
YesNo