Jump to content

file()


meltingpoint

Recommended Posts

Question one: of course it is much slower. PHP must split the file content into lines and pack it to arrays, and this takes some time. With feof() and fread() you simply read the file, you can process it on the fly or do something else with it. I remember a topic on one discussion group long ago - the guy complained about "very slow XML processing". He had a 10 MB file and tried to parse it with PHP, which took several minutes. He provided the source code and the next person noticed that he loads everything with file(), and then concatenates the whole array back to a string. After replacing this code with fopen() and fread(), the script became much faster and processed the same XML file in 2 seconds :).

 

You should avoid using file() unless you absolutely need the functionality it provides, especially for bigger files.

Link to comment
https://forums.phpfreaks.com/topic/174023-file/#findComment-917333
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.