Make WordPress Core

Changeset 44506


Ignore:
Timestamp:
01/09/2019 09:50:19 AM (8 years ago)
Author:
pento
Message:

Filesystem: Improve wp_is_stream() performance.

Instead of turning the return value of stream_get_wrappers() into a regex to match the scheme, we can instead extract the scheme and search the return value of stream_get_wrappers().

Props schlessera, swissspidy.
Fixes #45553.

File:
1 edited

Legend:

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

    r44481 r44506  
    57075707 */
    57085708function wp_is_stream( $path ) {
    5709         if ( false === strpos( $path, '://' ) ) {
     5709        $scheme_separator = strpos( $path, '://' );
     5710
     5711        if ( false === $scheme_separator ) {
    57105712                // $path isn't a stream
    57115713                return false;
    57125714        }
    57135715
    5714         $wrappers    = stream_get_wrappers();
    5715         $wrappers    = array_map( 'preg_quote', $wrappers );
    5716         $wrappers_re = '(' . join( '|', $wrappers ) . ')';
    5717 
    5718         return preg_match( "!^$wrappers_re://!", $path ) === 1;
     5716        $stream = substr( $path, 0, $scheme_separator );
     5717
     5718        return in_array( $stream, stream_get_wrappers(), true );
    57195719}
    57205720
Note: See TracChangeset for help on using the changeset viewer.