tcjohans Posted October 4, 2007 Share Posted October 4, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/71758-does-fopen-per-se-read-the-entire-file-into-memory/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.