We will look at some of those choices. There are still big variations between the fastest and the slowest test when repeated several times in the same code execution.
The process is repeated to add another line, then the file is closed using fclose. You may need to increase the operating system file cache size. When a cache is flooded, the segment may be dropped and your next one byte read will drag the whole segment back in to memory.
PHP comes to the rescue again with the filesize function, which takes the name of a file to check, and returns its filesize in bytes - precisely what we're looking for. What is significant Disks used to store data in byte blocks then they switched to 1k segments internally.
After you map out the data and the range of access you need, you can pick the highest performance code for the task. You have to read the file in segments and decode the data yourself. The alternative is to use fread to get a small segment of data, process that, then perform another fread.