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- True if the request succeeded, false otherwise.
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
- Scaling
- Scales with input
- Instructions
- 71–111
- Plugin surface
- 1 hook
- Called by
- 0
Reaches an outbound HTTP request via wp_safe_remote_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 154.
Third-party callbacks on 'wp_http_ixr_client_headers' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- sqldatabase query
WP_HTTP_IXR_Client::query()this function does it - hookthird-party callbacks
apply_filters()called directly - httpoutbound HTTP request
wp_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.
| When | Instructions | Calls it makes |
|---|---|---|
!is_wp_error() | 71–77 | array_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–77 | array_shift(), ->getXml(), apply_filters(), wp_safe_remote_post(), is_wp_error(), ->get_error_code(), ->get_error_message(), headers() |
!is_wp_error() | 77–83 | array_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–83 | array_shift(), ->getXml(), apply_filters(), htmlspecialchars(), wp_safe_remote_post(), is_wp_error(), ->get_error_code(), ->get_error_message(), headers() |
!is_wp_error() | 78–96 | array_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–102 | array_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–105 | array_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–111 | array_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 154 | 71–111 | 10 | |
| 8.5 | 154 | 71–111 | 10 | |
| 8.4 | 154 | 71–111 | 10 | |
| 8.3 | 154 | 71–111 | 10 | |
| 8.2 | 154 | 71–111 | 10 | |
| 8.1 | 154 | 71–111 | 10 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 155 | 71–112 | 10 |
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:
- 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
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_safe_remote_post()Retrieves the raw response from a safe HTTP request using the POST method.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_remote_retrieve_response_code()Retrieves only the response code from the raw response.
- wp_remote_retrieve_body()Retrieves only the body from the raw response.
- IXR_Request::__construct()PHP5 constructor.
- IXR_Error::__construct()PHP5 constructor.
- IXR_Message::__construct()PHP5 constructor.
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.
Signature, return type and hooks compared across 5 parsed releases.
...$args parameter by adding it to the function signature.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.