[wp-trac] [WordPress Trac] #63858: Trigger the wp_cron action from the shutdown hook instead of the init hook to reduce TTFB (⏱️ Time To First Byte) and improve performance 📈

WordPress Trac noreply at wordpress.org
Wed Oct 1 23:02:50 UTC 2025


#63858: Trigger the wp_cron action from the shutdown hook instead of the init hook
to reduce TTFB (⏱️ Time To First Byte) and improve performance 📈
-------------------------+---------------------
 Reporter:  pmbaldha     |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  6.9
Component:  Cron API     |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+---------------------
Changes (by westonruter):

 * milestone:  Awaiting Review => 6.9


Comment:

 For reference: The `shutdown` action is triggered by
 `shutdown_action_hook()`, and `shutdown_action_hook` is added via
 `register_shutdown_function( 'shutdown_action_hook' )`.

 Of particular note in the [https://www.php.net/manual/en/function
 .register-shutdown-function.php PHP docs for
 register_shutdown_function()]:

 > Shutdown functions run separately from the time tracked by
 max_execution_time. That means even if a process is terminated for running
 too long, shutdown functions will still be called. Additionally, if the
 max_execution_time runs out while a shutdown function is running it will
 not be terminated.

 This would seem to address any concerns about whether slowness in
 `wp_remote_post()` noted in #63547 would end up preventing cron from being
 spawned.

 Additionally, I just checked the order in which things happen and an
 output buffer callback (such as is proposed in #43258) will be executed
 ''before'' `shutdown`. This means the buffer can be flushed to the client
 without waiting potentially for a slow `wp_remote_post()`. In other words,
 even if the performance of `wp_remote_post()` is not improved, this
 shouldn't hold up the page from being served.

 This being the case, we may then want to turn off the asynchronous nature
 of the cron spawning if it happens at `shutdown` specifically if we find
 that an async request doesn't always result in a successful spawn. But if
 we find that it is always spawned as expected, then no need to make it
 synchronous.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63858#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list