How does `fopen` before `rename` still reads the old content using PHP
The code below opens a file descriptor ($fp
) to a specific file, then I overwrite that file (using rename
) and then later I read the content of that file using fread
. What amazes me is that when reading the file using fread
it still points to the content of the original file (before being overwritten)! How does this happen? I think this could only be possible if fopen
made an entire copy of the file so it can be read later, but I cant believe fopen
makes and entire copy of the file because this would be very inneficient.
How does `fopen` before `rename` still reads the old content using PHP
The code below opens a file descriptor ($fp
) to a specific file, then I overwrite that file (using rename
) and then later I read the content of that file using fread
. What amazes me is that when reading the file using fread
it still points to the content of the original file (before being overwritten)! How does this happen? I think this could only be possible if fopen
made an entire copy of the file so it can be read later, but I cant believe fopen
makes and entire copy of the file because this would be very inneficient.