Registers _wp_cron() to run on the 'shutdown' action.
Description
The spawn_cron() function attempts to make a non-blocking loopback request to wp-cron.php (when alternative cron is not being used). However, the wp_remote_post() function does not always respect the timeout and blocking parameters. A timeout of 0.01 may end up taking 1 second. When this runs at the 'wp_loaded' action, it increases the Time To First Byte (TTFB) since the HTML cannot be sent while waiting for the cron request to initiate. Moving the spawning of cron to the 'shutdown' hook allows for the server to flush the HTML document to the browser while waiting for the request.
Uses · 4
did_action()Retrieves the number of times an action has been fired during the current request.
_wp_cron()Runs scheduled callbacks or spawns cron for all scheduled events.
add_action()Adds a callback function to an action hook.
doing_action()Returns whether or not an action hook is currently being processed.
Signature, return type and hooks compared across 5 parsed releases.
6.9.7
Return type changed from false|int|void to none.verified against source
6.9.0
The _wp_cron() callback is moved from 'wp_loaded' to the 'shutdown' action, unless ALTERNATE_WP_CRON is enabled; the function now always returns void.from the docblock
5.7.0
Functionality moved to _wp_cron() to which this becomes a wrapper.from the docblock
5.1.0
Return value added to indicate success or failure.from the docblock
2.1.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/cron.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.