wppaste
WordPress

WP_HTTP_IXR_Client::query( $args ): bool

Since
3.1.0, 5.5.0
Source
wp-includes/class-wp-http-ixr-client.php:56

Compatibility

WordPress
since 5.5.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

$args

Return value

bool

Performance profile

How much work a call to WP_HTTP_IXR_Client::query() 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_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
71–111

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

Plugin surface
1 hook

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

Called by
0

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

What it touches

  • sqldatabase queryWP_HTTP_IXR_Client::query()this function does it
  • hookthird-party callbacksapply_filters()called directly
  • httpoutbound HTTP requestwp_safe_remote_post()called directly

What one call costs · 8 distinct outcomes

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

WhenInstructionsCalls it makes
!is_wp_error()71–77array_shift(), ->getXml(), apply_filters(), wp_safe_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_code()
is_wp_error()71–77array_shift(), ->getXml(), apply_filters(), wp_safe_remote_post(), is_wp_error(), ->get_error_code(), ->get_error_message(), headers()
!is_wp_error()77–83array_shift(), ->getXml(), apply_filters(), htmlspecialchars(), wp_safe_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_code()
is_wp_error()77–83array_shift(), ->getXml(), apply_filters(), htmlspecialchars(), wp_safe_remote_post(), is_wp_error(), ->get_error_code(), ->get_error_message(), headers()
!is_wp_error()78–96array_shift(), ->getXml(), apply_filters(), wp_safe_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), ->parse()
!is_wp_error()84–102array_shift(), ->getXml(), apply_filters(), htmlspecialchars(), wp_safe_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), ->parse()
!is_wp_error()87–105array_shift(), ->getXml(), apply_filters(), wp_safe_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), htmlspecialchars(), wp_remote_retrieve_body(), ->parse()
!is_wp_error()93–111array_shift(), ->getXml(), apply_filters(), htmlspecialchars(), wp_safe_remote_post(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), htmlspecialchars(), wp_remote_retrieve_body(), ->parse()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev15471–11110
8.515471–11110
8.415471–11110
8.315471–11110
8.215471–11110
8.115471–111101 fewer instruction than PHP 7.4
7.415571–11210

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 · 1

One hook fires while WP_HTTP_IXR_Client::query() runs, in this order:

  1. apply_filters( wp_http_ixr_client_headers )filterline 81 (+25 into the body)

    Filters the headers collection to be sent to the XML-RPC server.

Uses · 8

Source code

	public function query( ...$args ) {		$method  = array_shift( $args );		$request = new IXR_Request( $method, $args );		$xml     = $request->getXml(); 		$port = $this->port ? ":$this->port" : '';		$url  = $this->scheme . '://' . $this->server . $port . $this->path;		$args = array(			'headers'    => array( 'Content-Type' => 'text/xml' ),			'user-agent' => $this->useragent,			'body'       => $xml,		); 		// Merge Custom headers ala #8145.		foreach ( $this->headers as $header => $value ) {			$args['headers'][ $header ] = $value;		} 		/**		 * Filters the headers collection to be sent to the XML-RPC server.		 *		 * @since 4.4.0		 *		 * @param string[] $headers Associative array of headers to be sent.		 */		$args['headers'] = apply_filters( 'wp_http_ixr_client_headers', $args['headers'] ); 		if ( false !== $this->timeout ) {			$args['timeout'] = $this->timeout;		} 		// Now send the request.		if ( $this->debug ) {			echo '<pre class="ixr_request">' . htmlspecialchars( $xml ) . "\n</pre>\n\n";		} 		$response = wp_safe_remote_post( $url, $args ); 		if ( is_wp_error( $response ) ) {			$errno       = $response->get_error_code();			$errorstr    = $response->get_error_message();			$this->error = new IXR_Error( -32300, "transport error: $errno $errorstr" );			return false;		} 		if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {			$this->error = new IXR_Error( -32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')' );			return false;		} 		if ( $this->debug ) {			echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";		} 		// Now parse what we've got back.		$this->message = new IXR_Message( wp_remote_retrieve_body( $response ) );		if ( ! $this->message->parse() ) {			// XML error.			$this->error = new IXR_Error( -32700, 'parse error. not well formed' );			return false;		} 		// Is the message a fault?		if ( 'fault' === $this->message->messageType ) {			$this->error = new IXR_Error( $this->message->faultCode, $this->message->faultString );			return false;		} 		// Message must be OK.		return true;	}

Changelog

Introduced in 3.1.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.

5.5.0
Formalized the existing ...$args parameter by adding it to the function signature.from the docblock
3.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/class-wp-http-ixr-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.