wppaste
WordPress

IXR_Message::parse()

Source
wp-includes/IXR/class-IXR-message.php:45

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.

Performance profile

How much work a call to IXR_Message::parse() 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
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
24–155

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

Plugin surface
2 hooks

Third-party callbacks on 'xmlrpc_element_limit', 'xmlrpc_chunk_parsing_size' 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

  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 9 distinct outcomes

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

WhenInstructionsCalls it makes
always24preg_replace(), substr_replace()
always47preg_replace(), substr_replace(), preg_replace(), substr_replace()
always62–64preg_replace(), substr_replace(), preg_replace(), substr_replace(), strcspn(), strtoupper()
$root_tag && !function_exists()78preg_replace(), substr_replace(), preg_replace(), substr_replace(), strcspn(), strtoupper(), function_exists(), substr_count()
$root_tag && function_exists()83preg_replace(), substr_replace(), preg_replace(), substr_replace(), strcspn(), strtoupper(), function_exists(), apply_filters(), substr_count()
$root_tag && !function_exists()127–142preg_replace(), substr_replace(), preg_replace(), substr_replace(), strcspn(), strtoupper(), function_exists(), xml_parser_create(), xml_parser_set_option(), apply_filters(), xml_parse()
$root_tag && function_exists()132–147preg_replace(), substr_replace(), preg_replace(), substr_replace(), strcspn(), strtoupper(), function_exists(), apply_filters(), xml_parser_create(), xml_parser_set_option(), apply_filters(), xml_parse()
$root_tag && !function_exists()135–150preg_replace(), substr_replace(), preg_replace(), substr_replace(), strcspn(), strtoupper(), function_exists(), substr_count(), xml_parser_create(), xml_parser_set_option(), apply_filters(), xml_parse()
$root_tag && function_exists()140–155preg_replace(), substr_replace(), preg_replace(), substr_replace(), strcspn(), strtoupper(), function_exists(), apply_filters(), substr_count(), xml_parser_create(), xml_parser_set_option(), apply_filters(), xml_parse()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev16224–15511
8.516224–15511
8.416224–1551123 fewer instructions than PHP 8.3
8.318529–17811
8.218529–17811
8.118529–178118 fewer instructions than PHP 7.4
7.419329–18211

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

2 hooks fire while IXR_Message::parse() runs, in this order:

  1. apply_filters( xmlrpc_element_limit )filterline 86 (+41 into the body)

    Filters the number of elements to parse in an XML-RPC response.

  2. apply_filters( xmlrpc_chunk_parsing_size )filterline 109 (+64 into the body)

    Filters the chunk size that can be used to parse an XML-RPC response message.

Uses · 2

  • __()Retrieves the translation of $text.
  • apply_filters()Calls the callback functions that have been added to a filter hook.

Source code

    function parse()    {        if ( ! function_exists( 'xml_parser_create' ) ) {            trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );            return false;        }         // first remove the XML declaration        // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages        $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 );        $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) );        if ( '' == $this->message ) {            return false;        }         // Then remove the DOCTYPE        $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 );        $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) );        if ( '' == $this->message ) {            return false;        }         // Check that the root tag is valid        $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) );        if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) {            return false;        }        if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) {            return false;        }         // Bail if there are too many elements to parse        $element_limit = 30000;        if ( function_exists( 'apply_filters' ) ) {            /**             * Filters the number of elements to parse in an XML-RPC response.             *             * @since 4.0.0             *             * @param int $element_limit Default elements limit.             */            $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit );        }        if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) {            return false;        }         $this->_parser = xml_parser_create();        // Set XML parser to take the case of tags in to account        xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);        // Set XML parser callback functions        xml_set_element_handler($this->_parser, array($this, 'tag_open'), array($this, 'tag_close'));        xml_set_character_data_handler($this->_parser, array($this, 'cdata'));         // 256Kb, parse in chunks to avoid the RAM usage on very large messages        $chunk_size = 262144;         /**         * Filters the chunk size that can be used to parse an XML-RPC response message.         *         * @since 4.4.0         *         * @param int $chunk_size Chunk size to parse in bytes.         */        $chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size );         $final = false;         do {            if (strlen($this->message) <= $chunk_size) {                $final = true;            }             $part = substr($this->message, 0, $chunk_size);            $this->message = substr($this->message, $chunk_size);             if (!xml_parse($this->_parser, $part, $final)) {                if (PHP_VERSION_ID < 80000) { // xml_parser_free() has no effect as of PHP 8.0.                    xml_parser_free($this->_parser);                }

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 7.1.0 tag, from src/wp-includes/IXR/class-IXR-message.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.