How to enable logging of wp_remote_get() & WP_Http

How to enable logging of HTTP requests made by WordPress, to get a better understanding of your site's behavior and performance.

How to enable logging of wp_remote_get() & WP_Http

To analyze performance of a WordPress site it can sometimes be insightful to know how wp_remote_get() and other functions that relies on WP_Http are used, and what external requests are happening in the background.

To enable logging of requests, one can use the hook http_api_debug like this for example:

function templ_http_api_debug_logger( $response, $context, $class, $parsed_args, $url ) {
    error_log( 'http_api_debug: '.$url );
}
add_action('http_api_debug', 'templ_http_api_debug_logger', 10, 5);

If you have WP_DEBUG and WP_DEBUG_LOG enabled, this will output to debug.log every time a request is made.

Leave a Reply

Your email address will not be published.