Hi guys, and girls for sure;)
I tried to parse huge csv file a little before and found interesting thing: fgetcsv is considerable slower than file processing – just take a look at my code, it was faster for me than just yummy fgetcsv():
$content = file_get_contents('somefile.csv'); $rows = explode("n", $content); foreach ($rows as $row) { $columns = explode(';', $row); // Making something with $columns } |
… and that’s it.
Books to read
|
Thanks man, I haven’t run any timing tests between the two issues but I’m switching to your method.
Either way I don’t like keeping fopen() handles for a long time, so I prefer just loading the file into RAM and processing it in the background.
One problem with your method is that any quoted-field may contain semi-colons, which will fail with explode()…
This atrilce went ahead and made my day.