php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14884 DOM XML hangs while trying to execute a lot of XPath expressions
Submitted: 2002-01-06 03:27 UTC Modified: 2002-01-08 13:01 UTC
From: flying at dom dot natm dot ru Assigned: cmv (profile)
Status: Closed Package: DOM XML related
PHP Version: 4.0.6 OS: Windows 2000
Private report: No CVE-ID: None
 [2002-01-06 03:27 UTC] flying at dom dot natm dot ru
Environment:
 - Windows 2000 Server (SP2)
 - Apache 1.3.22
 - PHP 4.0.6 (windows binaries from www.php.net) running as CGI

 Here is a small test case: 

test.xml:
=========
<?xml version="1.0"?>
<root>
    <node>
        <child id="1"/>
        <child id="2"/>
        <child id="3"/>
    </node>
</root>

test.php
========
<?php
$xml = xmldoc(join('',file('test.xml')));
$xml->xpath_init();
$ctx = xpath_new_context($xml);
for ($i=0;$i<100;$i++)
{
    echo $i."<br>";
    $nodes = xpath_eval($ctx,'count(//child[@id &lt; '.$i.'])');
};
?>

 As you can see, this code just tries to execute 100 XPath expressions for the same DOM XML object. And it hangs after ~12 iterations.

 This bug available only on Windows, this test case works well on Linux.

 It also seems to not work properly in PHP 4.1.0.

 Also this expression seems to be evaluated wrong, because it returns 'false' value instead of number of nodes. Here is small XSLT template, which generates correct results:

test.xsl
========
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

<xsl:template name="loop">
    <xsl:param name="counter">1</xsl:param>
    [<xsl:value-of select="$counter"/> - <xsl:value-of select="count(//child[@id &lt; $counter])"/>]
    <xsl:if test="$counter &lt; 100">
        <xsl:call-template name="loop"><xsl:with-param name="counter" select="$counter + 1"/></xsl:call-template>
    </xsl:if>
</xsl:template>

<xsl:template match="/">
    <xsl:call-template name="loop"/>
</xsl:template>

</xsl:stylesheet>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-08 13:01 UTC] cmv@php.net
This works fine in 4.1.1 under Linux.  I know there were several bug fixes in the DOMXML extension between 4.1.0 and 4.1.1.

I'd try upgrading to 4.1.1 first, and see if that solves your problems.

- Colin
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 16:01:30 2024 UTC