[wp-trac] [WordPress Trac] #47659: total_time not available through WordPress' HTTP API

WordPress Trac noreply at wordpress.org
Sun Jul 7 04:12:28 UTC 2019


#47659: total_time not available through WordPress' HTTP API
--------------------------+-----------------------------
 Reporter:  flexithemes   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  HTTP API      |    Version:  5.2.2
 Severity:  normal        |   Keywords:
  Focuses:  rest-api      |
--------------------------+-----------------------------
 I just submitted our [https://wordpress.org/plugins/seo-checklist/ SEO
 Checklist] plugin and as part of the process the WordPress Plugin
 directory team requires the following:

     WordPress comes with an extensive HTTP API that should be used instead
 of creating your own curl calls. It’s both faster and more extensive.
 It’ll fall back to curl if it has to, but it’ll use a lot of WordPress’
 native functionality first.

 However, the HTTP API doesn't appear to work for getting
 [[span(style=color: #FF0000, **total_time**)]], since total_time isn't in
 the header response.

 I tried getting it a variety of different ways with the HTTP API, but
 couldn't. I also looked through the documentation and searched online, but
 there's nothing about total_time using the HTTP API. One other developer
 tried it too and couldn't figure it out.

 Here's how I was doing it in CURL, which worked:

 {{{
         $ch = curl_init(site_url());

         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

         if(curl_exec($ch)) {
             $info = curl_getinfo($ch);
             $response_time = $info['total_time'];
         }

         curl_close($ch);
 }}}

 Here's one example of what doesn't work:

 {{{
         $result = wp_remote_get( site_url() );
         if ( is_array( $result ) ) {
             $headers = $result['headers']; // array of http header lines
         }
         $response_time = $headers['total_time'];
 }}}

 The above code is in the plugin in includes/class-seo-checks.php at line
 100. Because it doesn't work, the response time of the server isn't
 currently measured during its check.

 Here's [https://php.net/manual/en/function.curl-getinfo.php PHP's
 documentation on curl_getinfo()], which includes total_time as an opt.

 Here's [https://curl.haxx.se/libcurl/c/CURLINFO_TOTAL_TIME.html Curl's
 official documentation on total_time].

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47659>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list