Php's file_get_content won't destroy the file content read to the memory? A small program written by myself a few times ago: traversing the files in a specified folder and searching for the specified content PHPcode is very memory-consuming. an error occurs almost every time $ contentfile_get_contents ($ file ); success $ content; $ fpfopen ($ file, r php's file_get_content won't destroy the file content read to the memory?
A small program written for itself a while ago: traverses the files in the specified folder and searches for the specified content
PHP code
// This usage is very memory-consuming. an error occurs almost every time. $ content = file_get_contents ($ file); // success $ content = ''; $ fp = fopen ($ file, 'R'); $ content. = fread ($ fp, 10240); // even if there is no fclose (), the call within the function will still run smoothly
My guess is that file_get_contents () will not destroy the memory of the read file content after the call ends. But why? I don't think php developers are dumb than me, but it does look silly.
------ Solution --------------------
File_get_contents ()
Equivalent
Fopren ()
Fread (filesize ())
Fclose ()
That is, the file is read into the memory at a time. if a large file is encountered, there will be insufficient memory.
And you $ content. = fread ($ fp, 10240 );
It's not easy to read 10 kb each time.