wp_convert_hr_to_bytes( string $value ): int
- Since
- 2.3.0, 4.6.0
- Source
wp-includes/load.php:1687
Compatibility
- WordPress
- since 4.6.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$valuestring- A (PHP ini) byte value, either shorthand or ordinary.
Return value
int- An integer byte value.
Performance profile
How much work a call to wp_convert_hr_to_bytes() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 14–17
- Plugin surface
- None
- Called by
- 5
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 23.
Nothing here hands control to plugin code.
5 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_convert_hr_to_bytes() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14–17 | strtolower() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 23 | 14–17 | 3 | |
| 8.5 | 23 | 14–17 | 3 | |
| 8.4 | 23 | 14–17 | 3 | 14 fewer instructions than PHP 8.3 |
| 8.3 | 37 | 22–31 | 3 | |
| 8.2 | 37 | 22–31 | 3 | |
| 8.1 | 37 | 22–31 | 3 | |
| 7.4 | 37 | 22–31 | 3 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
Used by · 5
- WP_Debug_Data::get_wp_media()Gets the WordPress media section of the debug data.
- WP_Site_Health::get_test_file_uploads()Tests if 'file_uploads' directive in PHP.ini is turned off.
- wp_initial_constants()Defines initial WordPress constants.
- wp_max_upload_size()Determines the maximum upload size allowed in php.ini.
- wp_raise_memory_limit()Attempts to raise the PHP memory limit for memory intensive processes.
Source code
function wp_convert_hr_to_bytes( $value ) { $value = strtolower( trim( $value ) ); $bytes = (int) $value; if ( str_contains( $value, 'g' ) ) { $bytes *= GB_IN_BYTES; } elseif ( str_contains( $value, 'm' ) ) { $bytes *= MB_IN_BYTES; } elseif ( str_contains( $value, 'k' ) ) { $bytes *= KB_IN_BYTES; } // Deal with large (float) values which run into the maximum integer size. return min( $bytes, PHP_INT_MAX );}Changelog
Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/load.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.