Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to read large files in PHP?

I have to read CSV files line by line which can be 10 to 20 Meg. file() is useless and I have to find the quickest way.

I have tried with fgets(), which runs fine, but I don't know if it reads a small block each time I call it, or if it caches a bigger one and optimize file I/O. Do I have to try the fread() way, parsing EOL by myself?

like image 403
Cédric Girard Avatar asked Nov 18 '25 22:11

Cédric Girard


1 Answers

You ought to be using fgetcsv() if possible.

Otherwise, there is always fgets().

like image 135
gnud Avatar answered Nov 21 '25 12:11

gnud