WP_AI_Client_HTTP_Client::sendRequestWithOptions( WordPress\AiClientDependencies\Psr\Http\Message\RequestInterface $request, WordPress\AiClient\Providers\Http\DTO\RequestOptions $options ): WordPress\AiClientDependencies\Psr\Http\Message\ResponseInterface
- Since
- 7.0.0
- Source
wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php:99
Compatibility
- WordPress
- since 7.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 2 of the 5 tracked releases, added in 7.0.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$requestWordPress\AiClientDependencies\Psr\Http\Message\RequestInterface- The PSR-7 request.
$optionsWordPress\AiClient\Providers\Http\DTO\RequestOptions- Transport options for the request.
Return value
WordPress\AiClientDependencies\Psr\Http\Message\ResponseInterface- The PSR-7 response.
Performance profile
How much work a call to WP_AI_Client_HTTP_Client::sendRequestWithOptions() 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
- Expensive
- Scaling
- Constant
- Instructions
- 24–45
- Plugin surface
- None
- Called by
- 0
Reaches an outbound HTTP request via wp_safe_remote_request().
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 51.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- httpoutbound HTTP request
wp_safe_remote_request()called directly - hookthird-party callbacks
do_action()one call below WP_AI_Client_HTTP_Client::sendRequestWithOptions()
Further down the call graph this can also reach query, option, cache, serialize 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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_AI_Client_HTTP_Client::sendRequestWithOptions() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_wp_error() | 24 | ->prepare_wp_args(), ->getUri(), wp_safe_remote_request(), is_wp_error(), ->create_psr_response() |
is_wp_error() && !->get_error_code() | 42 | ->prepare_wp_args(), ->getUri(), wp_safe_remote_request(), is_wp_error(), __(), ->getMethod(), ->get_error_message(), sprintf(), ->get_error_code() |
is_wp_error() && ->get_error_code() | 45 | ->prepare_wp_args(), ->getUri(), wp_safe_remote_request(), is_wp_error(), __(), ->getMethod(), ->get_error_message(), sprintf(), ->get_error_code(), ->get_error_code() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 51 | 24–45 | 2 | |
| 8.5 | 51 | 24–45 | 2 | |
| 8.4 | 51 | 24–45 | 2 | |
| 8.3 | 51 | 24–45 | 2 | |
| 8.2 | 51 | 24–45 | 2 | |
| 8.1 | 51 | 24–45 | 2 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 52 | 24–46 | 2 |
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.
Uses · 6
- wp_safe_remote_request()Retrieves the raw response from a safe HTTP request.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- __()Retrieves the translation of $text.
- WP_AI_Client_HTTP_Client::prepare_wp_args()Prepares WordPress HTTP API arguments from a PSR-7 request.
- \WordPress\AiClient\Providers\Http\Exception\NetworkException::__construct()
- WP_AI_Client_HTTP_Client::create_psr_response()Creates a PSR-7 response from a WordPress HTTP response.
Source code
public function sendRequestWithOptions( RequestInterface $request, RequestOptions $options ): ResponseInterface { $args = $this->prepare_wp_args( $request, $options ); $url = (string) $request->getUri(); $response = wp_safe_remote_request( $url, $args ); if ( is_wp_error( $response ) ) { $message = sprintf( /* translators: 1: HTTP method (e.g. GET, POST). 2: Request URL. 3: Error message. */ __( 'Network error occurred while sending %1$s request to %2$s: %3$s' ), $request->getMethod(), $url, $response->get_error_message() ); throw new NetworkException( $message, // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped $response->get_error_code() ? (int) $response->get_error_code() : 0 ); } return $this->create_psr_response( $response ); }Changelog
Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.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.