0

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><![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!

Eugene
  • 4,197
  • 7
  • 37
  • 54
  • 1
    possible duplicate of [PHP what is the best approach to using XML? Need to create and parse XML responses](http://stackoverflow.com/questions/2060346/php-what-is-the-best-approach-to-using-xml-need-to-create-and-parse-xml-response) – Gordon Jan 21 '11 at 19:04
  • is php the only language you will consider? – vtd-xml-author Jan 21 '11 at 23:08

2 Answers2

1

http://www.php.net/xmlreader can process it without using a ton of memory.

goat
  • 31,486
  • 7
  • 73
  • 96
1

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

Kemrop
  • 309
  • 2
  • 4
  • 9
  • 2
    unsetting the memory limit wont add new RAM to the machine or circumvent any other outside-php restrictions in place – Gordon Jan 21 '11 at 19:05