Search code examples
phplarge-files

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?


Solution

  • You ought to be using fgetcsv() if possible.

    Otherwise, there is always fgets().