php - This code needs to loop over 3.5 million rows, how can I make it more efficient? -


I have a CSV file that has 3.5 million codes.
I should tell that it is only going to happen this once.

Looks like CSV

  age9tlg, rigfh34, ...  

This is my code:

  ini_set ('max_execution_time', 600); Ini_set ("memory_limit", "512m"); $ File_handle = fopen ("Weekly CSV", "R"); While {$ line_of_text = fgetcsv ($ file_handle); if (is_array ($ line_of_text) foreach ($ line_of_text $ as col) {if (($ col)) {mysql_query ( Enter in the `action_6_weekly` values ​​('$ col', '') or die (mysql_error ());}} and {if (empty ($ line_of_text)} {mysql_query (" `action_6_weekly` values ​​(' $ Line_of_text ',' ') or die (mysql_error ());}}} Fclose ($ file_handle);  

Is this code going to die partly on me? My memory and maximum execution time will be quite high?

NB: This code will be run on my localhost, and the database will be the same C is at the same time, therefore latency is not a problem.


Update:
Here is another possible implementation, it performs in bulk insertion of a 2000 record $ I = 0; $ Vals = array (); while ((FIF ($ file_handle)) $ {$ ($ file_handle)) Line_of_text = fgetcsv ($ file_handle); {If_array ($ line_of_text) foreach ($ line_of_text $ as col) {if (! Below ($ col) {if ($ i> 2000) {$ vals [] = "('$ col', '')"; $ I ++; } And {$ vals = implode (',', $ vals); Mysql_query ("Enter value in action_6_wek $ vals") or die (mysql_error ()); $ Vals = array (); $ I = 0; }}} And {if (empty ($ line_of_text)} {if ($ i> 2000) {$ vals [] = "('$ line_of_text', '')"; $ I ++; } And {$ vals = implode (',', $ vals); Mysql_query ("Enter value in action_6_wek $ vals") or die (mysql_error ()); $ Vals = array (); $ I = 0; }}}} Fclose ($ file_handle);

If I want to use this method, can I determine the highest value to include it at one time?


Update 2
So, I found that

  load data local INFILE 'C: \\ xampp \ \ Htdocs \\ Weekly 'csv' can be used by the ';' set by the 'action_6_quickly' field '' Avoid '\\' fixed by lines, '(`code`)  

But this issue is now, I was wrong about the CSV format, this is actually 4 Code and then a line break, hence freefllogy, qporlfg, vcalpfx, rplfigc, vapworf, flofigx, apqoeei, clxosrc,
...

so I should be able to specify two rows ending Given - this question has been equated.


Update 3
Setting it to insert bulk of 20k rows

  while ($ feof ( $ File_handle)) {$ val [] = fgetcsv ($ file_handle); $ I ++; If ($ i == 20000) // // insert // set $ I = 0; // $ val = array ();}} // (for the last few rows which do not go up to 20k  

but this dies at this point because for some reason $ There are 75 lines in the vine, and why consider?
Note that the above code is simplified.

I suspect it would be the popular answer, but if I run on a CSV file it will be my php applicati, of course it is more optimized than what you have to do in php


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -