diff --git a/admin/include/functions.php b/admin/include/functions.php index 3d8ffa756..f587c3028 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -625,6 +625,28 @@ function get_fs_directories($path, $recursive = true) return $dirs; } +/** + * returns the size (in bytes) of a filesystem directory + * + * @since 11 + * @param string path + * @return int + */ +function get_fs_directory_size($path) +{ + $bytestotal = 0; + $path = realpath($path); + + if ($path !== false && $path != '' && file_exists($path)) + { + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) + { + $bytestotal += $object->getSize(); + } + } + return $bytestotal; +} + /** * save the rank depending on given categories order * diff --git a/admin/intro.php b/admin/intro.php index 987491eda..a3bb94f44 100644 --- a/admin/intro.php +++ b/admin/intro.php @@ -388,15 +388,22 @@ if (isset($result[0]['SUM(filesize)'])) $data_storage['Formats'] = $result[0]['SUM(filesize)']; } -//If the host is not windows, get the cache size -if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') +// PHP 5.5.19 is the oldest version get_fs_directory_size was tested on +if (version_compare(PHP_VERSION, '5.5.19') >= 0) { - $f = './_data'; - $io = popen ( '/usr/bin/du -sk ' . $f, 'r' ); - $size = fgets ($io, 4096); - $size = substr ( $size, 0, strpos ( $size, "\t" ) ); - pclose ( $io ); - $data_storage['Cache'] = $size; + if (!isset($_SESSION['cachedir_info']) or $_SESSION['cachedir_info']['calculated_on'] < strtotime('5 minutes ago')) + { + $start_time = get_moment(); + + $_SESSION['cachedir_info'] = array( + 'size' => get_fs_directory_size($conf['data_location']), + 'calculated_on' => time(), + ); + + $logger->debug('[admin/intro::'.__LINE__.'] cache size calculated in '.get_elapsed_time($start_time, get_moment()).' ('.$_SESSION['cachedir_info']['size'].' bytes)'); + } + + $data_storage['Cache'] = $_SESSION['cachedir_info']['size'] / 1000; } //Calculate total storage