The PHP Function Fread
The php function fread is used to read the content of an open file. It works with another function called fopen() which is used to open the file to be read. It is also possible to read the contents of a file without opening it via a different function called file_get_contents().
Basically, fread takes two parameters: the file handle to read from (which is the return value of fopen()) and the number of bytes to read. When it reads data from the file, PHP advances the array cursor by one byte for every byte that is read in. It stops reading when either the end of the file is reached or the number of bytes specified in parameter two is exceeded - whichever occurs first.
PHP will return the fread() result as a string, so it is easy to use in your scripts. It is a very fast way to get a lot of text into memory at once. This can be helpful if you need to send some data to the browser for download.
Be careful to limit the number of bytes that are fetched at any time. fread is "greedy" and will try to read as much data at once as it can. This can cause problems when working over a latent network. It is generally best to transfer blocks of data that are as small as possible at a time and use ob_flush() after each block to clear the Apache server's memory.