I have an array in php which is populated via XML. this array holds roughly 21000 items.
I am currently looping through the array, checking if the name node exists in the database (mysql) if it does update it, else insert new data and store the row id of the inserted/updated row, i then in the same loop insert more data into another table and link it to the first table: http://pastebin.com/iiyjkkuy
the array looks like this: http://pastebin.com/xcnHxeLk
Now due to the large amount of nodes in the array (21000) this is exceeding the 300 sec (5 mins) max execution time on my dev system..
What is the best way to loop through an array of this size and insert data?
just some more information on this. I am using expression engine 1.8.6 (work reasons) and i have to use its built in database class.
the reason for the select statements before each insert/update is to grab the row ID for future statements. The data has to be structured in the DB in a certain way, for example:
each source node has a papergroup node - this needs inserting / updating first then each paper name node needs to be linked to the paper group in the same table sourceid etc are then inserted into a sources table with a link to there parent paper in the papers table so basic db schema is this: papergroup inserted into papers table paper name inserted into papers table with papers.PID as the link to the papger group papers.ID sources are inserted into the sources table and linked to papers table on source.paperID
the basic structure of the XML source that populates the array is as follows:
<sources>
<source>
<sourceid>1</sourceid>
<papername>test</papername>
<papergroup>test group</papergroup>
<papertype>Standard</papertype>
<sourcename> test source</sourcename>
<sourcesize>page</sourcesize>
</source>
</sources>
the above is not a full segment but it shows the point about all the information being sent in one section. Hope this helps.
Ok I manage to get some timings. It takes 1:35:731 to get the XML it then takes between 0:0:025 and 0:0:700 to do an array loop (select, insert/update)