I’m reading the code of cron.php
in wp-includes and spawn_cron()
seems to be the one which actually executes registered tasks.
The last two lines of the function:
$cron_url = site_url( 'wp-cron.php?doing_wp_cron=' . $doing_wp_cron );
wp_remote_post( $cron_url, array( 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters( 'https_local_ssl_verify', true ) ) );
It simply opens wp-cron.php passing a task an as a query argument.
The description of the API at the top of cron.php:
* Schedules a hook which will be executed once by the WordPress actions core at
* a time which you specify. The action will fire off when someone visits your
* WordPress site, if the schedule time has passed.`
My question is that let’s say the visitor opens one of the pages of the site and then the registered task is fired by the cron API. And if the task is heavy and takes several minutes to complete, does the visitor gets a page that is not completely loaded until the task finishes?
[Edit]
To clarify what I’m asking, the question is, does the WP Cron API run tasks after the page loading completes?
With the below sample plugin, I confirmed that the above code (I quoted in the question as well) is the one actually calls scheduled tasks. It sets 0.0.1 timeout and accesses to wp-cron.php. This means if there are 100 tasks it takes 1 seconds to load all tasks. So it has a slight impact on the page loading speed. But it seems to be something not to worry about too much.
The cron job should not effect your viewer at all. If it does find a new hosting company.