Code Modernization: Use `file_get_contents()` in `get_file_data()`.
`file_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 [12044], [49073], [52696]. Props maxkellermann. See #55069. Built from https://develop.svn.wordpress.org/trunk@52698 git-svn-id: http://core.svn.wordpress.org/trunk@52287 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
fbb9d52774
commit
8a62f7dc05
|
@ -6566,16 +6566,10 @@ function wp_scheduled_delete() {
|
|||
* @return string[] Array of file header values keyed by header name.
|
||||
*/
|
||||
function get_file_data( $file, $default_headers, $context = '' ) {
|
||||
// We don't need to write to the file, so just open for reading.
|
||||
$fp = fopen( $file, 'r' );
|
||||
// Pull only the first 8 KB of the file in.
|
||||
$file_data = file_get_contents( $file, false, null, 0, 8 * KB_IN_BYTES );
|
||||
|
||||
if ( $fp ) {
|
||||
// Pull only the first 8 KB of the file in.
|
||||
$file_data = fread( $fp, 8 * KB_IN_BYTES );
|
||||
|
||||
// PHP will close file handle, but we are good citizens.
|
||||
fclose( $fp );
|
||||
} else {
|
||||
if ( false === $file_data ) {
|
||||
$file_data = '';
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.0-alpha-52697';
|
||||
$wp_version = '6.0-alpha-52698';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue