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 if 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():