recurse_dirsize example

// 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 ( 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';

                // Stop total size calculation.

function get_dirsize( $directory$max_execution_time = null ) {

    /* * Exclude individual site directories from the total when checking the main site of a network, * as they are subdirectories and should not be counted. */
    if ( is_multisite() && is_main_site() ) {
        $size = recurse_dirsize( $directory$directory . '/sites', $max_execution_time );
    } else {
        $size = recurse_dirsize( $directory, null, $max_execution_time );
    }

    return $size;
}

/** * Gets the size of a directory recursively. * * Used by get_dirsize() to get a directory size when it contains other directories. * * @since MU (3.0.0) * @since 4.3.0 The `$exclude` parameter was added. * @since 5.2.0 The `$max_execution_time` parameter was added. * @since 5.6.0 The `$directory_cache` parameter was added. * * @param string $directory Full path of a directory. * @param string|string[] $exclude Optional. Full path of a subdirectory to exclude from the total, * or array of paths. Expected without trailing slash(es). * Default null. * @param int $max_execution_time Optional. Maximum time to run before giving up. In seconds. * The timeout is global and is measured from the moment * WordPress started to load. Defaults to the value of * `max_execution_time` PHP setting. * @param array $directory_cache Optional. Array of cached directory paths. * Defaults to the value of `dirsize_cache` transient. * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. */
Home | Imprint | This part of the site doesn't use cookies.