wppaste
WordPress

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

Reaches the database via IXR_Client::query().

Scaling
Scales with input

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

Instructions
64–114

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • sqldatabase queryIXR_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.

WhenInstructionsCalls it makes
always64–68array_shift(), ->getLength(), ->getXml(), fsockopen()
always70–74array_shift(), ->getLength(), ->getXml(), htmlspecialchars(), fsockopen()
!feof()86–90array_shift(), ->getLength(), ->getXml(), fsockopen(), fputs(), feof(), fgets()
feof()86–102array_shift(), ->getLength(), ->getXml(), fsockopen(), fputs(), feof(), ->parse()
feof()92–108array_shift(), ->getLength(), ->getXml(), fsockopen(), fputs(), feof(), htmlspecialchars(), ->parse()
!feof()92–96array_shift(), ->getLength(), ->getXml(), htmlspecialchars(), fsockopen(), fputs(), feof(), fgets()
feof()92–108array_shift(), ->getLength(), ->getXml(), htmlspecialchars(), fsockopen(), fputs(), feof(), ->parse()
feof()98–114array_shift(), ->getLength(), ->getXml(), htmlspecialchars(), fsockopen(), fputs(), feof(), htmlspecialchars(), ->parse()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev17364–11414
8.517364–11414
8.417364–114145 fewer instructions than PHP 8.3
8.317864–11414
8.217864–11414
8.117864–11414
7.417864–11414

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

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.

  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
1.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.