Opened 8 years ago
Closed 8 years ago
#45553 closed enhancement (fixed)
Improve wp_is_stream() performance
| Reported by: | swissspidy | Owned by: | pento |
|---|---|---|---|
| Priority: | low | Milestone: | 5.1 |
| Component: | Filesystem API | Version: | |
| Severity: | minor | Keywords: | has-patch |
| Cc: | Focuses: |
Description
The wp_is_stream() function (used by functions like wp_normalize_path() currently uses a dynamically constructed regex to detect streams. This could be verified a lot by using in_array() instead.
@schlessera suggested the following version over at https://github.com/wp-cli/wp-cli/issues/5008:
function wp_is_stream( $path ) { $scheme_separator = strpos( $path, '://' ); if ( false === $scheme_separator ) { // $path isn't a stream return false; } $stream = substr( $path, 0, $scheme_separator ); return in_array( $stream, stream_get_wrappers(), true ); }
A quick benchmark shows that this is around four times faster than the current method.
Attachments (1)
Change History (3)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
In 44506: