diff options
Diffstat (limited to 'libs/Utils/Misc.class.php')
-rw-r--r-- | libs/Utils/Misc.class.php | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/libs/Utils/Misc.class.php b/libs/Utils/Misc.class.php index ae4b6d1..e2fe7cb 100644 --- a/libs/Utils/Misc.class.php +++ b/libs/Utils/Misc.class.php @@ -2,24 +2,24 @@ class Misc { - /** - * Returns human size - */ + /** + * Returns human size + */ public static function getSize($filesize, $precision = 2) { $units = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'); - + foreach ($units as $idUnit => $unit) { if ($filesize > 1024) - $filesize /= 1024; + $filesize /= 1024; else break; } return round($filesize, $precision).' '.$units[$idUnit].'B'; } - + /** * Returns hostname @@ -31,6 +31,26 @@ class Misc /** + * Returns CPU cores number + */ + public static function getCpuCoresNumber() + { + if (!($num_cores = shell_exec('/bin/grep -c ^processor /proc/cpuinfo'))) + { + if (!($num_cores = trim(shell_exec('/usr/bin/nproc')))) + { + $num_cores = 1; + } + } + + if ((int)$num_cores <= 0) + $num_cores = 1; + + return (int)$num_cores; + } + + + /** * Returns server IP */ public static function getLanIp() |