If a user visits a site and his visit triggers a cron job that is quite intensive, the page load speed will be slower for him right? As I understand the page doesn't wait for the cron job to execute before loading, but since the cron job would be running in parallel, it might still be the case that the page loads slower since the server is busy right?

  • Have a read up on spawn_cron which might help you: codex.wordpress.org/Function_Reference/spawn_cron – TomC Dec 10 '13 at 18:31
  • If your cron job is heavy enough to make server busy then it is heavy enough to make server busy. I don't quite follow what is your question - to confirm that? – Rarst Dec 10 '13 at 18:58
  • Yes I just wanted to confirm that, since I've been reading that page loads and cron jobs run independently and so the page load isn't affected. However if as you say the cron job is heavy enough it will affect page load as a side effect. – urok93 Dec 11 '13 at 16:30

Short answer - Nope. Any page request initializes the scheduled queue. It's just an initialize request. Wp-cron request is a standalone request.

so requesting URL /somepage you just initialize request to /wp-cron.php

However - If cron event doesn't work really well (it's has 1000 db queries e.g. or its requesting a some really long-to-respond resource), or both, or re-scheduling cron event for each request... just like any other http request it will eat resources, CPU performance, memory, etc... if it eats enough resources, your page will become slower.


The short answer is actually yes, in most cases.

Firstly, on most set-ups, spawning a cron job incurs a 1 second delay on page load, because it is done via a loopback HTTP request with a 1 second timeout - see https://wordpress.org/support/topic/save-a-full-second-on-cron-execution/.

Secondly, the spawned job will now be competing with the page load for database access (as well as other resources). Multiple processes can read the database concurrently; however, whenever a process is writing to the database, by default it is locked to prevent simultaneous write or read access by any other process - see https://stackoverflow.com/questions/1005206/does-sqlite-lock-the-database-file-on-reads#answer-1005218. The impact of this depends how complex the cron job's database updates are and how long the database is actually locked for, and may be insignificant. Of course, it would also be an issue if a cron job happened to be running when a page is requested, but having cron jobs spawned on page load guarantees they'll affect at least that page load.

If your server/hosting permits, you are recommended to set up a scheduled cron job to run every few hours, with the command

php -q /path/to/wp-cron.php

and disable cron spawning on page load with the following entry in wp-config.php:

define('DISABLE_WP_CRON', true);
  • 1
    This is the real answer. – ILikeTurtles Dec 14 '17 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.