dongweicha6077 2015-07-23 11:48
浏览 82

PHP XMLReader跳过大型XML文件

I try to proceed a large xml file (about 1.5 GB) with about 3 million items with PHP XMLReader. But the script stops randomly between 2,3 and 2,6 million items without an error.

There is no time or memory limit.

set_time_limit(0);
ini_set('max_execution_time', 0);
ini_set('memory_limit', -1);
error_reporting(E_ALL);

This is the code:

$Reader = new XMLReader();
$Reader->open('file.xml', NULL, LIBXML_PARSEHUGE);

$count = 0;

while ($Reader->read()) {
    if ($Reader->nodeType == XMLReader::ELEMENT && $Reader->name == 'file') {
        $outerXml = $Reader->readOuterXml();
        $count ++;
        echo $count . "
";
    }
}

echo 'end';

XMLReader seems to have some kind of restriction. I already tried the LIBXML_PARSEHUGE option but with no success.

Anyone has an idea?

Thanks!

UPDATE: It seems to be a problem with http curl via SSH, even with --max-time option set. It works with when running directly through the PHP parser.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于Lammps建模的描述
    • ¥15 #lingo#请问一下为什么会出现以下情况,是因为l第一个值是0的缘故吗?
    • ¥15 设计格雷码同步八进制计数器
    • ¥100 改写matlab程序(关键词-系统对)
    • ¥15 函数信号发生器仿真电路
    • ¥15 Qt的pixmap和image图片加载都导致程序崩溃怎么办
    • ¥15 Kali木马生成问题求解
    • ¥30 求一下解题思路,完全不懂
    • ¥15 C51单片机串口控制JQ6500语音模块
    • ¥30 想给yolo5模型加一个图片识别界面,但是图片还没有检测出来就闪退了