【发布时间】:2011-02-26 18:16:56
【问题描述】:
我有一个大约 12mb 的 XML 文件,其中包含大约 16000 个产品。我需要将其处理成数据库;但是,在大约 6000 行时,它会因 500 错误而死。 我正在使用 Kohana 框架(第 3 版)以防万一。
这是我在控制器中的代码:
$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 是商店的一堆商品,因此两个查询是 a) insert ignore 商店本身和 b) 插入产品
任何见解将不胜感激。
【问题讨论】:
标签: php xml domdocument large-files xmlreader