我有一个大约12mb的XML文件,其中大约有16000个产品。我需要将它处理成一个数据库;然而,在大约6000行时,它会以500错误而死亡。 我正在使用Kohana框架(版本3),以防万一与它有任何关系。如何在大型XML文件中使用XMLReader/DOMDocument并防止500错误
这里是我的代码,我有控制器内部:
$xml = new XMLReader();
$xml->open("path/to/file.xml");
$doc = new DOMDocument;
// Skip ahead to the first <product>
while ($xml->read() && $xml->name !== 'product');
// Loop through <product>'s
while ($xml->name == 'product')
{
$node = simplexml_import_dom($doc->importNode($xml->expand(), true));
// 2 queries to database put here
$xml->next('product');
}
的XML是AA一堆物品的商店,所以这两个查询是一个)insert ignore
商店本身和b)插入产品
任何有识之士将不胜感激。
啊,我没有想到这一点。我已经添加了,现在它运行良好。 – 2011-02-26 18:32:28