[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:32:20 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:  2.1
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+---------------------
Changes (by westonruter):

 * keywords:  has-patch => has-patch needs-testing
 * version:   => 2.1


Comment:

 The rationale for moving from `shutdown` to `init` is explained in r3561
 as follows:

 > Move wp_cron from shutdown hook to init. It was acting all funky (in the
 bad way) in the shutdown hook.

 It would be nice to know what was funky about this. This commit was 20
 years ago as part of WordPress 2.1. As of that commit, `spawn_crom()`
 looked like this:

 {{{#!php
 <?php
 function spawn_cron() {
         if (array_shift(array_keys(get_option('cron'))) > time()) return;

         $cron_url = get_settings('siteurl') . '/wp-cron.php';
         $parts = parse_url($cron_url);
         $argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'],
 $errno, $errstr, 0.01);
         if ( $argyle )
                 fputs($argyle, "GET {$parts['path']}?time=" . time() .
 '&check='
                 . md5(DB_PASS . '187425') . " HTTP/1.0\r\nHost:
 {$_SERVER['HTTP_HOST']}\r\n\r\n");
 }
 }}}

 It could be that `fsockopen()` would fail during a shutdown at that time.
 Back then, the latest version of PHP was 5.1.2. But that's just a guess.

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


More information about the wp-trac mailing list