PHP: how to parse a huge xml file
I need to parse a huge XML that contains lots of job entries, like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<items>
<item>
<title>&l开发者_JS百科t;![CDATA[...]]></title>
<description><![CDATA[...]]></description>
<link><![CDATA[...]]></link>
<city><![CDATA[...]]></city>
<state><![CDATA[...]]></state>
<position><![CDATA[...]]></position>
<company><![CDATA[...]]></company>
<category_id><![CDATA[...]]></category_id>
<job_id>...</job_id>
<salary><![CDATA[...]]></salary>
<term><![CDATA[...]]></term>
</item>
....
</items>
The server has enough memory to fully read that file but when if comes to parsing, it fails with "memory exhausted" error. Does PHP provide ways that would allow to split that file nicely or parse it in parts or anything that can be of help here. Thanks for any ideas and suggestions!
http://www.php.net/xmlreader can process it without using a ton of memory.
Have you tried ramping up the memory?
ini_set("memory_limit", "128M")
place this code at the top of your php file. you can set the memory as high as you want
精彩评论