我遇到PHP simplexml_load_string命令在大字符串上失败的问题。我想测试在命令失败之前可以解析多少个字符。这段代码适合这样的测试吗?有人可以提出更好的建议吗?
<?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";
与php.ini中的php memory_limit vale一起测试。