From 1e1fb78c07c0c095155d5f562bce3ee875781561 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 12 Feb 2022 13:13:59 +0000 Subject: [PATCH] Code Modernization: Use `file_get_contents()` in `wp_get_webp_info()`. `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 [50810], [52696], [52698], [52701]. Props maxkellermann. See #55069. Built from https://develop.svn.wordpress.org/trunk@52718 git-svn-id: http://core.svn.wordpress.org/trunk@52307 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 7 ++----- wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 2c818596c7..5d791eb1d0 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -5235,15 +5235,12 @@ function wp_get_webp_info( $filename ) { return compact( 'width', 'height', 'type' ); } - $handle = fopen( $filename, 'rb' ); + $magic = file_get_contents( $filename, false, null, 0, 40 ); - if ( false === $handle ) { + if ( false === $magic ) { return compact( 'width', 'height', 'type' ); } - $magic = fread( $handle, 40 ); - fclose( $handle ); - // Make sure we got enough bytes. if ( strlen( $magic ) < 40 ) { return compact( 'width', 'height', 'type' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 101912a18e..459cc58b18 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-52717'; +$wp_version = '6.0-alpha-52718'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.