如何在大型XML文件中使用XMLReader/DOMDocument并防止500错误 [英] How to use XMLReader/DOMDocument with large XML file and prevent 500 error

查看:116
本文介绍了如何在大型XML文件中使用XMLReader/DOMDocument并防止500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大约12mb的XML文件,其中包含大约16000个产品.我需要将其处理到数据库中;但是,它在大约6000行时死于500个错误. 我正在使用Kohana框架(版本3),以防与之有关.

I have an XML file that is approximately 12mb which has about 16000 product's. I need to process it into a database; however, at about 6000 rows it dies with a 500 error. I'm using the Kohana framework (version 3) just in case that has anything to do with it.

这是我在控制器内的代码:

Here's my code that I have inside the controller:

$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)插入产品

The XML is a a bunch of items for a store, so the two queries are a) insert ignore the store itself and b) insert the product

任何见识将不胜感激.

推荐答案

可能是内存不足.尝试增加您的内存限制

Probably you are running out of memory. Try to increase your memory limit

ini_set('memory_limit','128M');

或需要多少内存(取决于您的服务器). 我在这里为您提供了一些链接,这些链接还有其他增加服务器内存限制的方法:

or whatever the amount of memory is neccesary (it depends on your server). I leave you here some links with other ways of increasing the memory limit of your server:

PHP:增加内存限制

PHP:增加内存限制2

这篇关于如何在大型XML文件中使用XMLReader/DOMDocument并防止500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆