From 734960733e91cac19078709c5aca3c59028446b4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 11 Feb 2022 15:50:05 +0000 Subject: [PATCH] Code Modernization: Use `file_get_contents()` in `wp_get_image_mime()`. `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]. Props maxkellermann. See #55069. Built from https://develop.svn.wordpress.org/trunk@52701 git-svn-id: http://core.svn.wordpress.org/trunk@52290 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 8 +------- wp-includes/version.php | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 24cfbb7b33..18ce7c2fec 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3265,12 +3265,8 @@ function wp_get_image_mime( $file ) { return $mime; } - $handle = fopen( $file, 'rb' ); - if ( false === $handle ) { - return false; - } + $magic = file_get_contents( $file, false, null, 0, 12 ); - $magic = fread( $handle, 12 ); if ( false === $magic ) { return false; } @@ -3289,8 +3285,6 @@ function wp_get_image_mime( $file ) { ) { $mime = 'image/webp'; } - - fclose( $handle ); } catch ( Exception $e ) { $mime = false; } diff --git a/wp-includes/version.php b/wp-includes/version.php index edcadd7361..10a057c5a0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-52700'; +$wp_version = '6.0-alpha-52701'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.