Make WordPress Core

Changeset 52718


Ignore:
Timestamp:
02/12/2022 01:12:22 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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: PHP Manual: file_get_contents().

Follow-up to [50810], [52696], [52698], [52701].

Props maxkellermann.
See #55069.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r52717 r52718  
    52365236    }
    52375237
    5238     $handle = fopen( $filename, 'rb' );
    5239 
    5240     if ( false === $handle ) {
     5238    $magic = file_get_contents( $filename, false, null, 0, 40 );
     5239
     5240    if ( false === $magic ) {
    52415241        return compact( 'width', 'height', 'type' );
    52425242    }
    5243 
    5244     $magic = fread( $handle, 40 );
    5245     fclose( $handle );
    52465243
    52475244    // Make sure we got enough bytes.
Note: See TracChangeset for help on using the changeset viewer.