WP_Http::request( string $url, string|array $args = array() ): array|WP_Error
- Since
- 2.7.0
- Source
wp-includes/class-wp-http.php:169
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: 5How long the connection should stay open in seconds.$redirectionintdefault: 5Number 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: falseWhether to pass URLs through wp_http_validate_url().$blockingbooldefault: trueWhether 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 arrayArray or string of headers to send with the request.$cookiesarraydefault: empty arrayList of cookies to send with the request.$bodystring|arraydefault: nullBody to send with the request.$compressbooldefault: falseWhether to compress the $body when sending the request.$decompressbooldefault: trueWhether 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: trueWhether to verify SSL for the request.$sslcertificatesstringdefault: ABSPATH . WPINC . '/certificates/ca-bundle.crt'Absolute path to an SSL certificate .crt file.$streambooldefault: falseWhether 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: nullFilename of the file to write to when streaming. $stream must be set to true.$limit_response_sizeintdefault: nullSize 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\CaseInsensitiveDictionaryResponse headers keyed by name.$bodystringResponse body.$responsearrayArray of HTTP response data.$codeint|falseHTTP response status code.$messagestring|falseHTTP response message. } @type WP_Http_Cookie[] $cookies Array of cookies set by the server.$filenamestring|nullOptional. Filename of the response.$http_responseWP_HTTP_Requests_Response|nullResponse 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
- Scaling
- Constant
- Instructions
- 113–279
- Plugin surface
- 10 hooks
- Called by
- 3
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 400.
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.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($args) && isset($parsed_args) && $pre === false && !function_exists() && empty($url) | 113 | apply_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–235 | apply_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–239 | apply_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–242 | apply_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(), ::normalize_cookies(), 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–241 | apply_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–231 | apply_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(), ::processHeaders(), 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–246 | apply_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(), ::normalize_cookies(), 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–245 | apply_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–235 | apply_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(), ::processHeaders(), 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–248 | apply_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(), ::normalize_cookies(), 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–238 | apply_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(), ::processHeaders(), timeout(), function_exists(), ::normalize_cookies(), 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–237 | apply_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(), ::processHeaders(), 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–253 | apply_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–252 | apply_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(), ::normalize_cookies(), 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–242 | apply_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(), ::processHeaders(), timeout(), function_exists(), ::normalize_cookies(), 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–241 | apply_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(), ::processHeaders(), 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–244 | apply_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(), ::processHeaders(), timeout(), function_exists(), ::normalize_cookies(), 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–260 | apply_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(), ::normalize_cookies(), 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–259 | apply_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–249 | apply_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(), ::processHeaders(), 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–248 | apply_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(), ::processHeaders(), timeout(), function_exists(), ::normalize_cookies(), 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–266 | apply_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–266 | apply_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(), ::normalize_cookies(), 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–256 | apply_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(), ::processHeaders(), timeout(), function_exists(), ::normalize_cookies(), 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–255 | apply_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(), ::processHeaders(), 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–273 | apply_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(), ::normalize_cookies(), 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–272 | apply_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–262 | apply_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(), ::processHeaders(), 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–262 | apply_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(), ::processHeaders(), timeout(), function_exists(), ::normalize_cookies(), 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–279 | apply_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(), ::normalize_cookies(), 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–269 | apply_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(), ::processHeaders(), timeout(), function_exists(), ::normalize_cookies(), 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–268 | apply_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(), ::processHeaders(), 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–275 | apply_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(), ::processHeaders(), timeout(), function_exists(), ::normalize_cookies(), 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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 400 | 113–279 | 29 | |
| 8.5 | 400 | 113–279 | 29 | |
| 8.4 | 400 | 113–279 | 29 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 402 | 113–266 | 29 | |
| 8.2 | 402 | 113–266 | 29 | |
| 8.1 | 402 | 113–266 | 29 | |
| 7.4 | 402 | 113–266 | 29 |
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:
- apply_filters( http_request_timeout )filterline 181 (+12 into the body)
Filters the timeout value for an HTTP request.
- apply_filters( http_request_redirection_count )filterline 191 (+22 into the body)
Filters the number of redirects allowed during an HTTP request.
- apply_filters( http_request_version )filterline 201 (+32 into the body)
Filters the version of the HTTP protocol used in a request.
- apply_filters( http_headers_useragent )filterline 211 (+42 into the body)
Filters the user agent value sent with an HTTP request.
- apply_filters( http_request_reject_unsafe_urls )filterline 221 (+52 into the body)
Filters whether to pass URLs through wp_http_validate_url() in an HTTP request.
- apply_filters( http_request_args )filterline 252 (+83 into the body)
Filters the arguments used in an HTTP request.
- apply_filters( pre_http_request )filterline 277 (+108 into the body)
Filters the preemptive return value of an HTTP request.
- do_action( http_api_debug )actionline 297 (+128 into the body)
Fires after an HTTP API response is received and before the response is returned.
- do_action( http_api_debug )actionline 305 (+136 into the body)
Fires after an HTTP API response is received and before the response is returned.
- do_action( http_api_debug )actionline 322 (+153 into the body)
Fires after an HTTP API response is received and before the response is returned.
- apply_filters( https_ssl_verify )filterline 398 (+229 into the body)
Filters whether SSL should be verified for non-local requests.
- do_action( http_api_debug )actionline 441 (+272 into the body)
Fires after an HTTP API response is received and before the response is returned.
- apply_filters( http_response )filterline 468 (+299 into the body)
Filters a successful HTTP API response immediately before the response is returned.
Uses · 21
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_bloginfo()Retrieves information about the current site.
- wp_parse_args()Merges user defined arguments into defaults array.
- wp_http_validate_url()Validates a URL as safe for use in the HTTP API.
- wp_kses_bad_protocol()Sanitizes a string and removed disallowed URL protocols.
- __()Retrieves the translation of $text.
- do_action()Calls the callback functions that have been added to an action hook.
- get_temp_dir()Determines a writable directory for temporary files.
- wp_is_writable()Determines if a directory is writable.
- mbstring_binary_safe_encoding()Sets the mbstring internal encoding to a binary safe encoding when func_overload is enabled.
- reset_mbstring_encoding()Resets the mbstring internal encoding to a users previously set encoding.
- is_wp_error()Checks whether the given variable is a WordPress Error.
Show all 21
- WP_Error::__construct()Initializes the error.
- WP_Http::block_request()Determines whether an HTTP API request to the given URL should be blocked.
- WP_Http::processHeaders()Transforms header string into an array.
- WP_HTTP_Requests_Hooks::__construct()Constructor.
- WP_Http::normalize_cookies()Normalizes cookies for using in Requests.
- WP_HTTP_Proxy::__construct()
- \WpOrg\Requests\Proxy\Http::__construct()
- \WpOrg\Requests\Requests::request()
- WP_HTTP_Requests_Response::__construct()Constructor.
Used by · 3
- WP_Http::get()Uses the GET HTTP method.
- WP_Http::head()Uses the HEAD HTTP method.
- WP_Http::post()Uses the POST HTTP method.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.