wppaste
WordPress

IXR_Server::serve( $data = false )

Source
wp-includes/IXR/class-IXR-server.php:38

Compatibility

WordPress
core
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

$dataoptional
Default: false

Performance profile

How much work a call to IXR_Server::serve() 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

Reads or writes the filesystem via file_get_contents().

Scaling
Constant

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

Instructions
45–83

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

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

  • filesystemfilesystem accessfile_get_contents()called directly
  • hookthird-party callbacksapply_filters()one call below IXR_Server::serve()

What one call costs · 24 distinct outcomes

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

WhenInstructionsCalls it makes
->parse() && !is_a()45->parse(), ->call(), is_a(), ->getXml(), ->output()
->parse() && is_a()48->parse(), ->call(), is_a(), ->error(), ->getXml(), ->output()
!is_a()49->parse(), ->error(), ->call(), is_a(), ->getXml(), ->output()
->parse() && !is_a()52–56file_get_contents(), ->parse(), ->call(), is_a(), ->getXml(), ->output()
is_a()52->parse(), ->error(), ->call(), is_a(), ->error(), ->getXml(), ->output()
!->parse() && !is_a()53->parse(), ->error(), ->error(), ->call(), is_a(), ->getXml(), ->output()
->parse() && is_a()55–59file_get_contents(), ->parse(), ->call(), is_a(), ->error(), ->getXml(), ->output()
!is_a()56–60file_get_contents(), ->parse(), ->error(), ->call(), is_a(), ->getXml(), ->output()
!->parse() && is_a()56->parse(), ->error(), ->error(), ->call(), is_a(), ->error(), ->getXml(), ->output()
is_a()59–63file_get_contents(), ->parse(), ->error(), ->call(), is_a(), ->error(), ->getXml(), ->output()
!->parse() && !is_a()60–64file_get_contents(), ->parse(), ->error(), ->error(), ->call(), is_a(), ->getXml(), ->output()
!->parse() && is_a()63–67file_get_contents(), ->parse(), ->error(), ->error(), ->call(), is_a(), ->error(), ->getXml(), ->output()
12 further outcomes, up to 83 instructions
isset($value) && !function_exists() && ->parse() && !is_a()66function_exists(), header(), exit(), file_get_contents(), ->parse(), ->call(), is_a(), ->getXml(), ->output()
isset($value) && !function_exists() && ->parse() && is_a()69function_exists(), header(), exit(), file_get_contents(), ->parse(), ->call(), is_a(), ->error(), ->getXml(), ->output()
isset($value) && !function_exists() && !is_a()70function_exists(), header(), exit(), file_get_contents(), ->parse(), ->error(), ->call(), is_a(), ->getXml(), ->output()
isset($value) && function_exists() && ->parse() && !is_a()72function_exists(), status_header(), header(), header(), exit(), file_get_contents(), ->parse(), ->call(), is_a(), ->getXml(), ->output()
isset($value) && !function_exists() && is_a()73function_exists(), header(), exit(), file_get_contents(), ->parse(), ->error(), ->call(), is_a(), ->error(), ->getXml(), ->output()
isset($value) && !function_exists() && !->parse() && !is_a()74function_exists(), header(), exit(), file_get_contents(), ->parse(), ->error(), ->error(), ->call(), is_a(), ->getXml(), ->output()
isset($value) && function_exists() && ->parse() && is_a()75function_exists(), status_header(), header(), header(), exit(), file_get_contents(), ->parse(), ->call(), is_a(), ->error(), ->getXml(), ->output()
isset($value) && function_exists() && !is_a()76function_exists(), status_header(), header(), header(), exit(), file_get_contents(), ->parse(), ->error(), ->call(), is_a(), ->getXml(), ->output()
isset($value) && !function_exists() && !->parse() && is_a()77function_exists(), header(), exit(), file_get_contents(), ->parse(), ->error(), ->error(), ->call(), is_a(), ->error(), ->getXml(), ->output()
isset($value) && function_exists() && is_a()79function_exists(), status_header(), header(), header(), exit(), file_get_contents(), ->parse(), ->error(), ->call(), is_a(), ->error(), ->getXml(), ->output()
isset($value) && function_exists() && !->parse() && !is_a()80function_exists(), status_header(), header(), header(), exit(), file_get_contents(), ->parse(), ->error(), ->error(), ->call(), is_a(), ->getXml(), ->output()
isset($value) && function_exists() && !->parse() && is_a()83function_exists(), status_header(), header(), header(), exit(), file_get_contents(), ->parse(), ->error(), ->error(), ->call(), is_a(), ->error(), ->getXml(), ->output()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8345–837
8.58345–837
8.48345–8372 more instructions than PHP 8.3
8.38117–677
8.28117–677
8.18117–677
7.48117–677

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

Used by · 1

Source code

    function serve($data = false)    {        if (!$data) {            if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {                if ( function_exists( 'status_header' ) ) {                    status_header( 405 ); // WP #20986                    header( 'Allow: POST' );                }                header('Content-Type: text/plain'); // merged from WP #9093                die('XML-RPC server accepts POST requests only.');            }             $data = file_get_contents('php://input');        }        $this->message = new IXR_Message($data);        if (!$this->message->parse()) {            $this->error(-32700, 'parse error. not well formed');        }        if ($this->message->messageType != 'methodCall') {            $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');        }        $result = $this->call($this->message->methodName, $this->message->params);         // Is the result an error?        if (is_a($result, 'IXR_Error')) {            $this->error($result);        }         // Encode the result        $r = new IXR_Value($result);        $resultxml = $r->getXml();         // Create the XML        $xml = <<<EOD<methodResponse>  <params>    <param>      <value>      $resultxml      </value>    </param>  </params></methodResponse> EOD;      // Send it      $this->output($xml);    }

Changelog

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.

About this page

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