When running WordPress Cron manually, it shows WP-Cron spawning is disabled. What is WP-Cron spawning?

I use Ubuntu 20.04 LEMP stack VPS. In this server, I run 13 WordPress sites. Every 10 minutes I have set up to run each site cron job with a 20 seconds interval. So every site does not execute cron jobs exact same time.

I edited crontab using the following command.

crontab -u www-data -e 

When I go to the WordPress cron event plugin page, it shows The DISABLE_WP_CRON constant is set to true. WP-Cron spawning is disabled.

What is WP-Cron spawning? and can I enable it while using define('DISABLE_WP_CRON', true);

my crontab script sample.

while ! wget -q -O - https://example.com/wp-cron.php?doing_wp_cron /dev/null 21 ; do sleep 2 ; done ; echo ok

Topic wp-cron Wordpress

Category Web


What is WP-Cron spawning?

First off, let's see what WP-Cron is and how it works:

  • WP-Cron is how WordPress handles scheduling time-based tasks in WordPress, e.g. checking for core updates and publishing scheduled post.

  • WP-Cron works by checking, on every page load, a list of scheduled tasks to see what needs to be run.

  • Any tasks due to run will be called during that page load.

    And at this point, a cron spawning might happen, whereby WP-Cron would send a request to run cron through HTTP request that does not halt page loading. And note that the request is sent to wp-cron.php, e.g. https://example.com/wp-cron.php.

So WP-Cron spawning is basically an automatic cron call that happens on page load. See _wp_cron() and spawn_cron().

Therefore, if you manually run WordPress cron, then you should disable the automatic cron call since it will contribute to extra resource usage on your server. See Hooking WP-Cron Into the System Task Scheduler.

And thus, there should be no need to worry regarding the message that says WP-Cron spawning is disabled — it is probably merely a notice/reminder, or that the plugin might simply be trying to make a test cron request, but then did not proceed when it noticed WP-Cron spawning is disabled.

Nonetheless, if the spawning is disabled, then ensure that WordPress cron is still being executed properly, e.g. via the cron daemon in Linux and MacOS systems.

can I enable it while using define('DISABLE_WP_CRON', true);

WP-Cron spawning is enabled by default, but it can be disabled/enabled via the DISABLE_WP_CRON constant:

  • Disables cron spawning — define('DISABLE_WP_CRON', true);
  • Enables cron spawning — define('DISABLE_WP_CRON', false);

However, if you have access to the system's task scheduler (to make a web request to the wp-cron.php file), then you should just disable WP-Cron spawning.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.