I am having trouble handling memory efficiently in a PHP script I have written that parses XML and then imports it into a database.
There are a very large amount of XML files, roughly 4-5 million. The arrays of parsed data that I'm building inside the parser are becoming too large and the script just gets killed by the server.
Currently my script does the following:
1) Loads each XML file individually
2) Store relevant data in objects in an array
3) Go through all objects and build SQL query
4) Use PDO driver to start transaction and import data
The arrays become so big that the script just says 'Killed'. In this scenario, is the only option to buy a more powerful server or is there a way to optimize these massive arrays to make sure that the script still runs fast but doesn't crash?