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

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.