0

I am having trouble with PHP simplexml_load_string command failing on large strings. I would like to test how many characters can be parsed before the command fails. Is this code suitable for such a test? can someone suggest better?

<?php
$string = "";
$increment = 0;

if (ob_get_level() == 0) ob_start();


        for ($x = 1; $x <= 500; $x++)
{
        $string = "<?xml version='1.0'?><new-wrapper>";
        for ($y = 0; $y <= $increment; $y++) {
                $string = $string .  "<content>some content</content>";
                }
        $string = $string .  "</new-wrapper>";
        echo " String length is<b> " . strlen($string) ."</b>";

        // $xml = simplexml_load_string($string);
        $xml = simplexml_load_string($tring, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_PARSEHUGE);

        $increment = $increment + 300;
        ob_flush();
        flush();
        usleep(100000);
}
echo "THE END";

To test in conjunction with php memory_limit vale in php.ini.

Mustapha George
  • 2,497
  • 9
  • 47
  • 79
  • Might be kind of duplicate of: http://stackoverflow.com/questions/5428055/xml-parse-huge-on-function-simplexml-load-string – Anticom Jun 11 '15 at 07:29
  • might be kind of... Here I am asking for code to test performance of a php command, not an alternative to the command. However i might end up going that route, but not without trying to understand why. – Mustapha George Jun 11 '15 at 11:09

0 Answers0