Jump to content

Does fopen() per se read the entire file into memory?


tcjohans

Recommended Posts

Hi,

 

This is just a quick question.

 

Could anyone confirm whether or not calling fopen() on a file per se means that all of it is read into memory. This is an important issue for me right now. In another thread, I have expressed the belief that I could fopen() a file and then fseek() to a given position and read some limited content there (e.g. by means of fgets() or fgetc()) without having to get the entire file into memory first (which would greatly slow down the process e.g. if dealing with very large files).

 

However, someone else expressed a contrary opinion:

"I may be mistaken, but I believe that it has to read the entire file into memory, then places the pointer at the beginning of the file at which point you can then call fseek() and go to the position you want. I don't see how PHP can just go to a particular place in a file without having at least read all data prior to the seek point in the file. fopen is the handle for the file. fseek, fgets, and all other file functions rely on this being called first. fopen read the entire file into memory and you can then work with that data. But you have to have the fopen handle first."

 

Can someone who knows this matter please put their two cents on this issue?

 

Thomas

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.