[wp-trac] [WordPress Trac] #47659: total_time not available through WordPress' HTTP API
WordPress Trac
noreply at wordpress.org
Mon Jul 8 02:49:49 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 | Resolution:
Keywords: close | Focuses:
--------------------------+------------------------------
Changes (by SergeyBiryukov):
* keywords: => close
Comment:
Hi @flexithemes, welcome to WordPress Trac! Thanks for the ticket.
You can use the `requests-curl.after_request` hook to get access to
`total_time` (where [source:tags/5.2.2/src/wp-
includes/Requests/Transport/cURL.php?marks=426#L424 curl.after_request] is
a Requests library hook, and the `requests-` prefix is added in
[source:tags/5.2.2/src/wp-includes/class-wp-http-requests-
hooks.php?marks=72#L43 WP_HTTP_Requests_Hooks::dispatch()] when mapping it
to a native WordPress action.
Here's an example that works for me;
{{{
class WP47659_Requests_Debug {
var $total_time;
function __construct() {
add_action( 'plugins_loaded', array( $this,
'perform_request' ) );
add_action( 'requests-curl.after_request', array( $this,
'store_total_time' ), 10, 2 );
}
function perform_request() {
wp_remote_get( 'https://www.google.com/' );
echo $this->total_time;
die();
}
function store_total_time( $headers, $info ) {
$this->total_time = $info['total_time'];
}
}
new WP47659_Requests_Debug;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47659#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list