IXR_Client::query( $args ): bool
- Since
- 1.5.0, 5.5.0
- Source
wp-includes/IXR/class-IXR-client.php:68
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 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 64–114
- Plugin surface
- None
- Called by
- 1
Reaches the database via IXR_Client::query().
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 173.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- sqldatabase query
IXR_Client::query()this function does it
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 IXR_Client::query() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 64–68 | array_shift(), ->getLength(), ->getXml(), fsockopen() |
| always | 70–74 | array_shift(), ->getLength(), ->getXml(), htmlspecialchars(), fsockopen() |
!feof() | 86–90 | array_shift(), ->getLength(), ->getXml(), fsockopen(), fputs(), feof(), fgets() |
feof() | 86–102 | array_shift(), ->getLength(), ->getXml(), fsockopen(), fputs(), feof(), ->parse() |
feof() | 92–108 | array_shift(), ->getLength(), ->getXml(), fsockopen(), fputs(), feof(), htmlspecialchars(), ->parse() |
!feof() | 92–96 | array_shift(), ->getLength(), ->getXml(), htmlspecialchars(), fsockopen(), fputs(), feof(), fgets() |
feof() | 92–108 | array_shift(), ->getLength(), ->getXml(), htmlspecialchars(), fsockopen(), fputs(), feof(), ->parse() |
feof() | 98–114 | array_shift(), ->getLength(), ->getXml(), htmlspecialchars(), fsockopen(), fputs(), feof(), htmlspecialchars(), ->parse() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 173 | 64–114 | 14 | |
| 8.5 | 173 | 64–114 | 14 | |
| 8.4 | 173 | 64–114 | 14 | 5 fewer instructions than PHP 8.3 |
| 8.3 | 178 | 64–114 | 14 | |
| 8.2 | 178 | 64–114 | 14 | |
| 8.1 | 178 | 64–114 | 14 | |
| 7.4 | 178 | 64–114 | 14 |
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 · 3
- IXR_Request::__construct()PHP5 constructor.
- IXR_Error::__construct()PHP5 constructor.
- IXR_Message::__construct()PHP5 constructor.
Used by · 1
Source code
function query( ...$args ) { $method = array_shift($args); $request = new IXR_Request($method, $args); $length = $request->getLength(); $xml = $request->getXml(); $r = "\r\n"; $request = "POST {$this->path} HTTP/1.0$r"; // Merged from WP #8145 - allow custom headers $this->headers['Host'] = $this->server; $this->headers['Content-Type'] = 'text/xml'; $this->headers['User-Agent'] = $this->useragent; $this->headers['Content-Length']= $length; foreach( $this->headers as $header => $value ) { $request .= "{$header}: {$value}{$r}"; } $request .= $r; $request .= $xml; // Now send the request if ($this->debug) { echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; } if ($this->timeout) { $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); } else { $fp = @fsockopen($this->server, $this->port, $errno, $errstr); } if (!$fp) { $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); return false; } fputs($fp, $request); $contents = ''; $debugContents = ''; $gotFirstLine = false; $gettingHeaders = true; while (!feof($fp)) { $line = fgets($fp, 4096); if (!$gotFirstLine) { // Check line for '200' if (strstr($line, '200') === false) { $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); return false; } $gotFirstLine = true; } if (trim($line) == '') { $gettingHeaders = false; } if (!$gettingHeaders) { // merged from WP #12559 - remove trim $contents .= $line; } if ($this->debug) { $debugContents .= $line; } } if ($this->debug) { echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; } // Now parse what we've got back $this->message = new IXR_Message($contents); 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 ($this->message->messageType == 'fault') { $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); return false; }Changelog
Introduced in 1.5.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 6.7.7 tag, from
src/wp-includes/IXR/class-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.