WP_Debug_Data::get_sizes(): array
- Since
- 5.2.0
- Source
wp-admin/includes/class-wp-debug-data.php:1832
wordpress (ABSPATH), plugins, themes, and uploads.Description
Intended to supplement the array returned by WP_Debug_Data::debug_data().
Compatibility
- WordPress
- since 5.2.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.
Return value
array- The sizes of the directories, also the database size and total installation size.
Performance profile
How much work a call to WP_Debug_Data::get_sizes() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 60–81
- Plugin surface
- None
- Called by
- 2
Reads stored settings via get_transient(), cached per request but not free on a cold cache.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 180.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Debug_Data::get_sizes() - transienttransient
get_transient()one call below WP_Debug_Data::get_sizes()
Further down the call graph this can also reach option, cache, serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Debug_Data::get_sizes() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$size_db | 60–65 | ::get_database_size(), wp_get_upload_dir(), ini_get(), untrailingslashit(), get_theme_root(), wp_get_font_dir(), array_values(), __(), __() |
$size_db | 68–73 | ::get_database_size(), wp_get_upload_dir(), ini_get(), untrailingslashit(), get_theme_root(), wp_get_font_dir(), array_values(), size_format(), __() |
$size_total !== null | 70–73 | ::get_database_size(), wp_get_upload_dir(), ini_get(), untrailingslashit(), get_theme_root(), wp_get_font_dir(), array_values(), __(), size_format() |
$size_db && $size_total !== null | 78–81 | ::get_database_size(), wp_get_upload_dir(), ini_get(), untrailingslashit(), get_theme_root(), wp_get_font_dir(), array_values(), size_format(), size_format() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 180 instructions, 60–81 executed per call, 13 branches. The work does not change between versions.
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 · 8
- wp_get_upload_dir()Retrieves uploads directory information.
- untrailingslashit()Removes trailing forward slashes and backslashes if they exist.
- get_theme_root()Retrieves path to themes directory.
- wp_get_font_dir()Retrieves font uploads directory information.
- __()Retrieves the translation of $text.
- recurse_dirsize()Gets the size of a directory recursively.
- size_format()Converts a number of bytes to the largest unit the bytes will fit into.
- WP_Debug_Data::get_database_size()Fetches the total size of all the database tables for the active database user.
Used by · 2
- WP_REST_Site_Health_Controller::get_directory_sizes()Gets the current directory sizes for this install.
- wp_ajax_health_check_get_sizes()Handles site health check to get directories and database sizes via AJAX.
Source code
public static function get_sizes() { $size_db = self::get_database_size(); $upload_dir = wp_get_upload_dir(); /* * We will be using the PHP max execution time to prevent the size calculations * from causing a timeout. The default value is 30 seconds, and some * hosts do not allow you to read configuration values. */ if ( function_exists( 'ini_get' ) ) { $max_execution_time = ini_get( 'max_execution_time' ); } /* * The max_execution_time defaults to 0 when PHP runs from cli. * We still want to limit it below. */ if ( empty( $max_execution_time ) ) { $max_execution_time = 30; // 30 seconds. } if ( $max_execution_time > 20 ) { /* * If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent * edge-case timeouts that may happen after the size loop has finished running. */ $max_execution_time -= 2; } /* * Go through the various installation directories and calculate their sizes. * No trailing slashes. */ $paths = array( 'wordpress_size' => untrailingslashit( ABSPATH ), 'themes_size' => get_theme_root(), 'plugins_size' => WP_PLUGIN_DIR, 'uploads_size' => $upload_dir['basedir'], 'fonts_size' => wp_get_font_dir()['basedir'], ); $exclude = $paths; unset( $exclude['wordpress_size'] ); $exclude = array_values( $exclude ); $size_total = 0; $all_sizes = array(); // Loop over all the directories we want to gather the sizes for. foreach ( $paths as $name => $path ) { $dir_size = null; // Default to timeout. $results = array( 'path' => $path, 'raw' => 0, ); // If the directory does not exist, skip checking it, as it will skew the other results. if ( ! is_dir( $path ) ) { $all_sizes[ $name ] = array( 'path' => $path, 'raw' => 0, 'size' => __( 'The directory does not exist.' ), 'debug' => 'directory not found', ); continue; } if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) { if ( 'wordpress_size' === $name ) { $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time ); } else { $dir_size = recurse_dirsize( $path, null, $max_execution_time ); } } if ( false === $dir_size ) { // Error reading. $results['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' ); $results['debug'] = 'not accessible';Changelog
Introduced in 5.2.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.7.7 tag, from
src/wp-admin/includes/class-wp-debug-data.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.