What is the difference between
$contents = file_get_contents("folder/somefile.txt")
and
$handle = fopen("folder/somefile.txt", "r");
$contents = fread($h开发者_JS百科andle, filesize($filename));
fclose($handle);
in terms of performance, file pointer handling and memory managing ?
And is it true that file_get_contents uses mmap
if OS allows it ?
fread has a limit on how many chars you can read, and its better for parsing data.
file_get_contents has no limit on the input (that I know of). This is used for external API access and such.
fread()
reads binary data, file_get_contents()
returns the data as a string.
Curious results! The file_get_contents() function is supposed to be a wrapper for fopen, but the decoupling of the fopen and fread seems to make performance slower. http://www.ebrueggeman.com/blog/php_benchmarking_fopen
精彩评论