I have large XML file (400 MB) and I need update it daily. For every main element I use SELECT + INSERT/UPDATE query into database. When I run script, it process 26 main elements per minute but it slows - after 500 main elements, it is much slower (10 elements per minute).
$xml_reader = new XMLReader;
$xml_reader->open("feed.xml");
// move the pointer to the first product
while ($xml_reader->read() && $xml_reader->name != 'SHOPITEM');
// loop through the products
while ($xml_reader->name == 'SHOPITEM')
{
// load the current xml element into simplexml and we’re off and running!
$feed = simplexml_load_string($xml_reader->readOuterXML());
// now you can use your simpleXML object ($xml).
//e.g. $feed->PRODUCTNO
//SELECT, UPDATE/INSERT HERE
}
// move the pointer to the next product
$xml_reader->next('SHOPITEM');
}
// don’t forget to close the file
$xml_reader->close();
This is the XML:
<?xml version="1.0" encoding="utf-8"?>
<SHOP>
<SHOPITEM>
<ITEM_ID>2600000394161</ITEM_ID>
(+ 15 more elements like this)
<PARAM>
<PARAM_NAME><![CDATA[some data here]]></PARAM_NAME>
<VAL><![CDATA[some data here]]></VAL>
</PARAM>
(+ 10 more elements like this)
</SHOPITEM>
(lot of shopitems here)
</SHOP>
I can't use SimpleXML due to my RAM. Is there any faster PHP XML parser or what way does it big sites (e.g. price compare sites)? Better HW? My CPU is on 10% and RAM on 80% when XML processing.