wppaste
WordPress

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
Sends a PSR-7 request with transport options and returns a PSR-7 response.

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

Reaches an outbound HTTP request via wp_safe_remote_request().

Scaling
Constant

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

Instructions
24–45

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • httpoutbound HTTP requestwp_safe_remote_request()called directly
  • hookthird-party callbacksdo_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.

WhenInstructionsCalls 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

PHPCompiledExecutedBranchesNotes
8.6-dev5124–452
8.55124–452
8.45124–452
8.35124–452
8.25124–452
8.15124–4521 fewer instruction than PHP 7.4
7.45224–462

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

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.

  1. 7.0.4
  2. 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.