Do WordPress cron jobs slow down page loading?

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x