Make WordPress Core


Ignore:
Timestamp:
02/09/2022 12:31:27 PM (3 years ago)
Author:
SergeyBiryukov
Message:

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

Follow-up to [12174].

Props maxkellermann.
See #55069.

File:
1 edited

Legend:

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

    r51919 r52696  
    218218         */
    219219        public function read_all() {
    220             $all = '';
    221             while ( ! $this->feof() ) {
    222                 $all .= $this->read( 4096 );
    223             }
    224             return $all;
     220            return stream_get_contents( $this->_f );
    225221        }
    226222    }
Note: See TracChangeset for help on using the changeset viewer.