ID: 42968
Updated by: [EMAIL PROTECTED]
Reported By: quaker at barbara dot eu dot org
Status: Wont fix
Bug Type: DOM XML related
Operating System: Linux 2.6.20, Ubuntu 7.04
PHP Version: 5.2.4
New Comment:
It does exist. dom binding is much more efficient than domxml so you
dont hit the PHP memory limit.
Previous Comments:
------------------------------------------------------------------------
[2007-10-16 04:42:43] quaker at barbara dot eu dot org
How does this bug not exists in 4.4.7 while it uses same XML library?
Below example code:
<?php
print "Current memory limit: " . ini_get("memory_limit") . "\n";
$dom = domxml_new_doc('1.0');
$responseElement = $dom->create_element('response');
$dom->append_child($responseElement);
/* Infinite loop */
while (1)
{
$dataElement = $dom->create_element('data');
$dataText = $dom->create_text_node('Example data');
$dataElement->append_child($dataText);
$responseElement->append_child($dataElement);
}
/* Never executed, just for showing idea */
$xmlString = $dom->dump_mem(true);
echo $xmlString;
?>
Result, as expected:
Allowed memory size of 2097152 bytes exhausted (tried to allocate 32
bytes) in XXX on line 14
Line 14 is:
$responseElement->append_child($dataElement);
------------------------------------------------------------------------
[2007-10-15 20:28:26] [EMAIL PROTECTED]
That memory is handled from within the libxml2 library. There is no
safe way to integrate the memory routines from PHP without adversely
affecting all other modules within the web server that rely on libxml2.
------------------------------------------------------------------------
[2007-10-15 08:31:32] quaker at barbara dot eu dot org
Description:
------------
DOMXML functions can allocate more memory than memory_limit allows.
Reproduce code:
---------------
<?php
print "Current memory limit: " . ini_get("memory_limit") . "\n";
$dom = new DOMDocument();
$responseElement = $dom->createElement('response');
$dom->appendChild($responseElement);
/* Infinite loop */
while (1)
{
$dataElement = $dom->createElement('data');
$dataText = $dom->createTextNode('Example data');
$dataElement->appendChild($dataText);
$responseElement->appendChild($dataElement);
}
/* Never executed, just for showing idea */
$xmlString = $dom->saveXML();
echo $xmlString;
?>
Expected result:
----------------
Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to
allocate XXX bytes) in YYY on line ZZZ
Actual result:
--------------
Memory limit is not hit. Script memory usage grows, till out of memory
received from OS.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42968&edit=1