开发者

What is the faster function to read files?

开发者 https://www.devze.com 2023-04-03 22:09 出处:网络
I am using fopen() and fread() to read files if( file_exists( $file ) ){ $open = fopen( $file , \'r\' );

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

0

精彩评论

暂无评论...
验证码 换一张
取 消