When to use readfile (), fread (), file_get_contents (), fgets ()?

fread () and ReadFile ()
fread () reads a performance maximum length 8k bytes, it can not be read as a one-time large files to download. Advantage is that the operation more flexible, each reading designated bytes of content for easy control server traffic while downloading.
readfile () advantage is the ability to read large files one time; PHP does not require pre-read memory, faster downloads directly to the processing of documents handed over to the server. The disadvantage that they can not control the load. So it is no memory limit if you encounter memory errors reported first call ob_end_flush () function like closed buffer.
file_get_contents is not readfile () faster because memory is gone php. But when reading small text into a string variable, the function most suitable for use, simpler, faster.
fgets () is reading a line from the file, and then process the file line by line when needed, using the

Guess you like

Origin www.cnblogs.com/cosiray/p/10949849.html