file() VS file_get_contents() which is better? PHP

php

Solution

They're unrelated, actually.

`file()` reads the file into an array by parsing EOL characters, while `file_get_contents()` actually reads the file contents into a string.

Also, this means you are at the mercy of the server operating system, since Windows EOL is different from Linux EOL (for example).

So, the first one is text-friendly, while the second one binary-friendly.

In short, don't try doing `file('image.png');`

Problem

I just want to know how to improve the speed of the web application I am creating. I am also open to other suggestions. fread or file_get_contents??

Original source