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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.