mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-07-07 02:11:26 +02:00
+ add a 5 minutes cache to avoid calculating cache size too often * tested with anold PHP 5.5 (could work with earlier versions, but I prefer to not take the risk)
This commit is contained in:
@@ -625,6 +625,28 @@ function get_fs_directories($path, $recursive = true)
|
|||||||
return $dirs;
|
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
|
* save the rank depending on given categories order
|
||||||
*
|
*
|
||||||
|
|||||||
+15
-8
@@ -388,15 +388,22 @@ if (isset($result[0]['SUM(filesize)']))
|
|||||||
$data_storage['Formats'] = $result[0]['SUM(filesize)'];
|
$data_storage['Formats'] = $result[0]['SUM(filesize)'];
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the host is not windows, get the cache size
|
// PHP 5.5.19 is the oldest version get_fs_directory_size was tested on
|
||||||
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
|
if (version_compare(PHP_VERSION, '5.5.19') >= 0)
|
||||||
{
|
{
|
||||||
$f = './_data';
|
if (!isset($_SESSION['cachedir_info']) or $_SESSION['cachedir_info']['calculated_on'] < strtotime('5 minutes ago'))
|
||||||
$io = popen ( '/usr/bin/du -sk ' . $f, 'r' );
|
{
|
||||||
$size = fgets ($io, 4096);
|
$start_time = get_moment();
|
||||||
$size = substr ( $size, 0, strpos ( $size, "\t" ) );
|
|
||||||
pclose ( $io );
|
$_SESSION['cachedir_info'] = array(
|
||||||
$data_storage['Cache'] = $size;
|
'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
|
//Calculate total storage
|
||||||
|
|||||||
Reference in New Issue
Block a user