What is the faster function to read files?
I am using fopen()
and fread()
to read files
if( file_exists( $file ) ){
$open = fopen( $file , 'r' );
return fread( $open , filesize( $file ) );
}
fclose( $file );
My files size is about 10 MB
So, I was wondering i开发者_StackOverflow社区f there was anything faster.
file_get_contents
seems to be faster, but in my searches I found it seems like it uses more ram memory... Which one should I use?
I would recommend you to use file_get_contents()
if all you want is to load the entire file into memory, since it's shorter and shows clearly what you are doing.
Also, from the PHP manual on file_get_contents()
:
file_get_contents()
is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
I'd use file_get_contents. I'd say user experience is main aspect you should think about
精彩评论