[wp-trac] [WordPress Trac] #63547: wp_remote_post not respecting timeout & blocking params

WordPress Trac noreply at wordpress.org
Sun Jun 8 21:06:43 UTC 2025


#63547: wp_remote_post not respecting timeout & blocking params
--------------------------+--------------------------
 Reporter:  mihai200      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:
Component:  HTTP API      |     Version:  6.7.2
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  performance
--------------------------+--------------------------
Changes (by westonruter):

 * status:  closed => reopened
 * focuses:   => performance
 * resolution:  reported-upstream =>


Comment:

 I'm re-opening this for us to track on the Performance team.

 Performance could be negatively impacted because
 [https://github.com/WordPress/wordpress-
 develop/blob/066431423ca6e1441eeb96777516445eb7b678ee/src/wp-
 includes/cron.php#L954-L969 WP Cron is spawned] with these args:

 {{{
 'timeout'   => 0.01,
 'blocking'  => false,
 }}}

 Since `wp_cron()` runs at the `init` action, which then schedules
 `_wp_cron()` to run at the `wp_loaded` action, meaning that if the
 loopback request takes longer than expected, every page load that spawns
 crawn will have a bad TTFB.

 ----

 What follows is what I had drafted before @TimothyBlynJacobs replied
 noting the existing issue in Requests.

 I created a
 [https://gist.github.com/westonruter/b66cfc51397c75d6497b6ed0aeb68ce3
 Sleepy Responses] plugin to help test this, where a response can be slowed
 down by 5 seconds by adding `?sleep=5` to the URL.

 I adapted your WP-CLI test script as follows (e.g. `try-http-api.php`):

 {{{#!php
 <?php
 $args = array(
         'timeout'   => 0.01,
         'blocking'  => false,
         'sslverify' => false,
 );

 $url = site_url( '/wp-cron.php?doing_wp_cron' );
 global $argv;
 if ( isset( $argv[3] ) ) {
         if ( str_starts_with( $argv[3], 'http://' ) || str_starts_with(
 $argv[3], 'https://' ) ) {
                 $url = $argv[3];
         } elseif ( str_starts_with( $argv[3], '/' ) ) {
                 $url = site_url( $argv[3] );
         } else {
                 WP_CLI::error( sprintf( 'Bad URL: %s', $argv[3] ) );
         }
 }

 $start     = microtime( true );
 $response  = wp_remote_post( $url, $args );
 $end       = microtime( true );
 $exec_time = $end - $start;

 WP_CLI::log( sprintf( 'Requested URL: %s', $url ) );
 WP_CLI::log( sprintf( 'Execution time: %s seconds', round( $exec_time, 4 )
 ) );
 if ( is_wp_error( $response ) ) {
         WP_CLI::error( sprintf( '%s (%s)', $response->get_error_message(),
 $response->get_error_code() ) );
 } elseif ( wp_remote_retrieve_response_code( $response ) ) {
         WP_CLI::error( sprintf( 'Expected non-blocking request to return
 empty response code but got %s', wp_remote_retrieve_response_code(
 $response ) ) );
 } elseif ( $end - $start > 0.1 ) {
         WP_CLI::error( 'Response took unexpected amount of time for non-
 blocking request.' );
 } else {
         WP_CLI::log( 'OK ✅' );
 }
 }}}

 Here's what I'm seeing:

 {{{
 $ wp eval-file try-http-api.php '/?sleep=3'
 Requested URL: http://localhost:8000/?sleep=3
 Execution time: 1.0174 seconds
 Error: Response took unexpected amount of time for non-blocking request.
 }}}

 {{{
 $ wp eval-file try-http-api.php 'https://wordpress.org/'
 Requested URL: https://wordpress.org/
 Execution time: 0.5602 seconds
 Error: Response took unexpected amount of time for non-blocking request.
 }}}

 Note that plugins aren't loaded in requests to `wp-cron.php` so if I
 manually edit the file to add a `sleep(3)` at the top, then I also get an
 error:

 {{{
 $ wp eval-file try-http-api.php '/wp-cron.php?doing_wp_cron'
 Requested URL: http://localhost:8000/wp-cron.php?doing_wp_cron
 Execution time: 1.0125 seconds
 Error: Response took unexpected amount of time for non-blocking request.
 }}}

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


More information about the wp-trac mailing list