1

What is the best way to sort large csv files in php, up to 5GB ? Should I use some CSVReader or use unix commands?

Andrius
  • 344
  • 3
  • 15

1 Answers1

1

PHP pages are usually made for processing quick web pages for browsers, for a file in GB and to not keep crashing into memory and time limits, call a unix command independently.

Here is a good reference to a similar question: https://stackoverflow.com/a/222445/6288442

" > /dev/null 2>/dev/null &"

That will redirect both stdio (first >) and stderr (2>) to /dev/null and run in the background.

There are other ways to do the same thing, but this is the simplest to read.

An alternative to the above double-redirect:

" &> /dev/null &"

and https://stackoverflow.com/a/223745/6288442

`echo "the command"|at now`;

As for the sort command: https://stackoverflow.com/a/9471139/6288442

sort --field-separator=';' --key=2,1,3

C. Geek
  • 347
  • 2
  • 16
  • 1
    performance using a unix command is usually always better since it runs directly on the shell as opposed to running over the php interpreter which is an extension on the web server you are using – C. Geek Dec 28 '17 at 07:14