wppaste
WordPress

WP_Http::request( string $url, string|array $args = array() ): array|WP_Error

Since
2.7.0
Source
wp-includes/class-wp-http.php:164
Send an HTTP request to a URI.

Description

Please note: The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS protocols.

Compatibility

WordPress
since 2.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$urlstring
The request URL.
$argsstring|arrayoptional
Array or string of HTTP request arguments.Default: array()
  • $methodstringdefault: 'GET'

    Request method. Accepts 'GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', or 'PATCH'. Some transports technically allow others, but should not be assumed.
  • $timeoutfloatdefault: 5

    How long the connection should stay open in seconds.
  • $redirectionintdefault: 5

    Number of allowed redirects. Not supported by all transports.
  • $httpversionstringdefault: '1.0'

    Version of the HTTP protocol to use. Accepts '1.0' and '1.1'.
  • $userstringdefault: 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' )

    -agent User-agent value sent.
  • $reject_unsafe_urlsbooldefault: false

    Whether to pass URLs through wp_http_validate_url().
  • $blockingbooldefault: true

    Whether the calling code requires the result of the request. If set to false, the request will be sent to the remote server, and processing returned to the calling code immediately, the caller will know if the request succeeded or failed, but will not receive any response from the remote server.
  • $headersstring|arraydefault: empty array

    Array or string of headers to send with the request.
  • $cookiesarraydefault: empty array

    List of cookies to send with the request.
  • $bodystring|arraydefault: null

    Body to send with the request.
  • $compressbooldefault: false

    Whether to compress the $body when sending the request.
  • $decompressbooldefault: true

    Whether to decompress a compressed response. If set to false and compressed content is returned in the response anyway, it will need to be separately decompressed.
  • $sslverifybooldefault: true

    Whether to verify SSL for the request.
  • $sslcertificatesstringdefault: ABSPATH . WPINC . '/certificates/ca-bundle.crt'

    Absolute path to an SSL certificate .crt file.
  • $streambooldefault: false

    Whether to stream to a file. If set to true and no filename was given, it will be dropped it in the WP temp dir and its name will be set using the basename of the URL.
  • $filenamestringdefault: null

    Filename of the file to write to when streaming. $stream must be set to true.
  • $limit_response_sizeintdefault: null

    Size in bytes to limit the response to.

Return value

array|WP_Error
Array of response data, or a WP_Error instance upon error.
  • $headers\WpOrg\Requests\Utility\CaseInsensitiveDictionary

    Response headers keyed by name.
  • $bodystring

    Response body.
  • $responsearray

    Array of HTTP response data.
    • $codeint|false

      HTTP response status code.
    • $messagestring|false

      HTTP response message. } @type WP_HTTP_Cookie[] $cookies Array of cookies set by the server.
    • $filenamestring|null

      Optional. Filename of the response.
    • $http_responseWP_HTTP_Requests_Response|null

      Response object.

Performance profile

How much work a call to WP_Http::request() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
113–279

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 396.

Plugin surface
10 hooks

Third-party callbacks on 'http_request_timeout', 'http_request_redirection_count', 'http_request_version' run inside this call, and their cost is not bounded by anything here.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below WP_Http::request()

Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 33 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Http::request() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && empty($url)113apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), __(), GET(), do_action()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && empty($parsed_args) && !->is_enabled()211–235apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && empty($parsed_args) && ->is_enabled() && !->send_through_proxy()215–239apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && !empty($parsed_args) && !->is_enabled()218–242apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && empty($parsed_args) && !->is_enabled() && !is_wp_error()219–241apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && empty($parsed_args) && !->is_enabled()220–231apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && !empty($parsed_args) && ->is_enabled() && !->send_through_proxy()222–246apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && empty($parsed_args) && ->is_enabled() && !->send_through_proxy() && !is_wp_error()223–245apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && empty($parsed_args) && ->is_enabled() && !->send_through_proxy()224–235apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !empty($parsed_args) && !->is_enabled() && !is_wp_error()226–248apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && !empty($parsed_args) && !->is_enabled()227–238apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && empty($parsed_args) && !->is_enabled() && !is_wp_error()228–237apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
21 further outcomes, up to 275 instructions
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && !->use_authentication()229–253apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !empty($parsed_args) && ->is_enabled() && !->send_through_proxy() && !is_wp_error()230–252apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && !empty($parsed_args) && ->is_enabled() && !->send_through_proxy()231–242apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && empty($parsed_args) && ->is_enabled() && !->send_through_proxy() && !is_wp_error()232–241apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !empty($parsed_args) && !->is_enabled() && !is_wp_error()235–244apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && !empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && !->use_authentication()236–260apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && !->use_authentication() && !is_wp_error()237–259apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && !->use_authentication()238–249apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !empty($parsed_args) && ->is_enabled() && !->send_through_proxy() && !is_wp_error()239–248apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && ->use_authentication()242–266apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), ->username(), ->password(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && !->use_authentication() && !is_wp_error()244–266apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && !empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && !->use_authentication()245–256apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && !->use_authentication() && !is_wp_error()246–255apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && !empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && ->use_authentication()249–273apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), ->username(), ->password(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && ->use_authentication() && !is_wp_error()250–272apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), ->username(), ->password(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && ->use_authentication()251–262apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), ->username(), ->password(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && !->use_authentication() && !is_wp_error()253–262apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && ->use_authentication() && !is_wp_error()257–279apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), ->username(), ->password(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !$parsed_args && !empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && ->use_authentication()258–269apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), ->username(), ->password(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && ->use_authentication() && !is_wp_error()259–268apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), ->username(), ->password(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && !empty($url) && !empty($parsed_url) && !->block_request() && !empty($parsed_args) && ->is_enabled() && ->send_through_proxy() && ->use_authentication() && !is_wp_error()266–275apply_filters(), apply_filters(), apply_filters(), get_bloginfo(), get_bloginfo(), apply_filters(), apply_filters(), wp_parse_args(), wp_parse_args(), apply_filters(), apply_filters(), function_exists(), parse_url(), ->block_request(), ::WP_Http(), timeout(), function_exists(), ::WP_Http(), apply_filters(), ->register(), ->is_enabled(), ->send_through_proxy(), ->host(), ->port(), ->register(), ->use_authentication(), ->username(), ->password(), mbstring_binary_safe_encoding(), ::WpOrg\\Requests\\Requests(), ->to_array(), reset_mbstring_encoding(), do_action(), is_wp_error(), apply_filters()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev396113–27929
8.5396113–27929
8.4396113–279292 fewer instructions than PHP 8.3
8.3398113–27929
8.2398113–27929
8.1398113–27929
7.4398113–27929

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 13

13 hooks fire while WP_Http::request() runs, in this order:

  1. apply_filters( http_request_timeout )filterline 176 (+12 into the body)

    Filters the timeout value for an HTTP request.

  2. apply_filters( http_request_redirection_count )filterline 186 (+22 into the body)

    Filters the number of redirects allowed during an HTTP request.

  3. apply_filters( http_request_version )filterline 196 (+32 into the body)

    Filters the version of the HTTP protocol used in a request.

  4. apply_filters( http_headers_useragent )filterline 206 (+42 into the body)

    Filters the user agent value sent with an HTTP request.

  5. apply_filters( http_request_reject_unsafe_urls )filterline 216 (+52 into the body)

    Filters whether to pass URLs through wp_http_validate_url() in an HTTP request.

  6. apply_filters( http_request_args )filterline 247 (+83 into the body)

    Filters the arguments used in an HTTP request.

  7. apply_filters( pre_http_request )filterline 272 (+108 into the body)

    Filters the preemptive return value of an HTTP request.

  8. do_action( http_api_debug )actionline 292 (+128 into the body)

    Fires after an HTTP API response is received and before the response is returned.

  9. do_action( http_api_debug )actionline 299 (+135 into the body)

    Fires after an HTTP API response is received and before the response is returned.

  10. do_action( http_api_debug )actionline 316 (+152 into the body)

    Fires after an HTTP API response is received and before the response is returned.

  11. apply_filters( https_ssl_verify )filterline 392 (+228 into the body)

    Filters whether SSL should be verified for non-local requests.

  12. do_action( http_api_debug )actionline 435 (+271 into the body)

    Fires after an HTTP API response is received and before the response is returned.

  13. apply_filters( http_response )filterline 462 (+298 into the body)

    Filters a successful HTTP API response immediately before the response is returned.

Uses · 21

Show all 21

Used by · 3

Source code

	public function request( $url, $args = array() ) {		$defaults = array(			'method'              => 'GET',			/**			 * Filters the timeout value for an HTTP request.			 *			 * @since 2.7.0			 * @since 5.1.0 The `$url` parameter was added.			 *			 * @param float  $timeout_value Time in seconds until a request times out. Default 5.			 * @param string $url           The request URL.			 */			'timeout'             => apply_filters( 'http_request_timeout', 5, $url ),			/**			 * Filters the number of redirects allowed during an HTTP request.			 *			 * @since 2.7.0			 * @since 5.1.0 The `$url` parameter was added.			 *			 * @param int    $redirect_count Number of redirects allowed. Default 5.			 * @param string $url            The request URL.			 */			'redirection'         => apply_filters( 'http_request_redirection_count', 5, $url ),			/**			 * Filters the version of the HTTP protocol used in a request.			 *			 * @since 2.7.0			 * @since 5.1.0 The `$url` parameter was added.			 *			 * @param string $version Version of HTTP used. Accepts '1.0' and '1.1'. Default '1.0'.			 * @param string $url     The request URL.			 */			'httpversion'         => apply_filters( 'http_request_version', '1.0', $url ),			/**			 * Filters the user agent value sent with an HTTP request.			 *			 * @since 2.7.0			 * @since 5.1.0 The `$url` parameter was added.			 *			 * @param string $user_agent WordPress user agent string.			 * @param string $url        The request URL.			 */			'user-agent'          => apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $url ),			/**			 * Filters whether to pass URLs through wp_http_validate_url() in an HTTP request.			 *			 * @since 3.6.0			 * @since 5.1.0 The `$url` parameter was added.			 *			 * @param bool   $pass_url Whether to pass URLs through wp_http_validate_url(). Default false.			 * @param string $url      The request URL.			 */			'reject_unsafe_urls'  => apply_filters( 'http_request_reject_unsafe_urls', false, $url ),			'blocking'            => true,			'headers'             => array(),			'cookies'             => array(),			'body'                => null,			'compress'            => false,			'decompress'          => true,			'sslverify'           => true,			'sslcertificates'     => ABSPATH . WPINC . '/certificates/ca-bundle.crt',			'stream'              => false,			'filename'            => null,			'limit_response_size' => null,		); 		// Pre-parse for the HEAD checks.		$args = wp_parse_args( $args ); 		// By default, HEAD requests do not cause redirections.		if ( isset( $args['method'] ) && 'HEAD' === $args['method'] ) {			$defaults['redirection'] = 0;		} 		$parsed_args = wp_parse_args( $args, $defaults );		/**		 * Filters the arguments used in an HTTP request.		 *		 * @since 2.7.0		 *

Changelog

Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/class-wp-http.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.