Code Modernization: Use stream_get_contents() in POMO_FileReader::read_all().

`stream_get_contents()` is faster than `fread()`, because the PHP core can decide how to best read the remaining file; it could decide to issue just one `read()` call or `mmap()` the file first.

Per the PHP manual, `file_get_contents()` or `stream_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 the OS to enhance performance.

Reference: [https://www.php.net/manual/en/function.file-get-contents.php PHP Manual: file_get_contents()].

Follow-up to [12174].

Props maxkellermann.
See .

git-svn-id: https://develop.svn.wordpress.org/trunk@52696 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-02-09 12:31:27 +00:00
parent b8f97013df
commit 89bcc4843a

@ -217,11 +217,7 @@ if ( ! class_exists( 'POMO_FileReader', false ) ) :
* @return string
*/
public function read_all() {
$all = '';
while ( ! $this->feof() ) {
$all .= $this->read( 4096 );
}
return $all;
return stream_get_contents( $this->_f );
}
}
endif;