diff options
author | ShevAbam <shevabam@gmail.com> | 2015-01-16 18:14:07 +0100 |
---|---|---|
committer | ShevAbam <shevabam@gmail.com> | 2015-01-16 18:14:07 +0100 |
commit | 3ed4c1d633f3ddfc50d921c5d5c19ebf7cf640c4 (patch) | |
tree | fe135c5868a41cecfae98294facb61accea76912 /libs/Utils | |
parent | c3ec82dd6f60ac8057cc50d9bf6274738db9c02e (diff) |
CPU : changes on retrieving CPU information
Load Average and CPU : fix on recovery the number of CPU cores
Last login : the datas are retrieved differently
Diffstat (limited to 'libs/Utils')
-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() |