I am trying to import huge .csv file into the database. It is Drupal database, I am importing products into the node, content_type_ and uc_products tables. But this is not so relevant as due to the performance optimization I stopped using Drupal functions node_load and/or node_save and I insert/update records directly via SQL commands.
Scenario:
- Read whole csv file from local server (approx. 40MB) into the variable (to prevent accessing the file per each record)
- Parse it to array per line
Parse every line to fields
Check if the record in database exists (1 SQL select, compare particular field)
- If exists, update it (1 SQL update)
If does not exists, insert it (3 inserts, 1 update)
6.1. If record has image code and it is different from the one in the database, download (curl) the new image file from external server and save it at the local server.
1 additional delayed insert to the log table
When I run this script, i got 502 Proxy error (Reason: Error reading from remote server) after approx. 10k imported records and the page stops loading. However, the import continues (new records are still being added into tables). This stops after 20k-26k (tried several times) records.
Two questions: What's that Proxy error and why am I getting one? How to optimize my script even more? Is there some other, usual way to import huge amount of data into the MySQL?
Thanks a lot.