diff options
author | ShevAbam <shevabam@gmail.com> | 2014-06-18 10:11:11 +0200 |
---|---|---|
committer | ShevAbam <shevabam@gmail.com> | 2014-06-18 10:11:11 +0200 |
commit | 20705a550df5b13a544dc0865c6aef16e64c99d9 (patch) | |
tree | e396dface41e30d39a68d5fe66097b1f8f641a81 /libs/cpu.php |
+ First commit (version 2.0)v2.0
Diffstat (limited to 'libs/cpu.php')
-rw-r--r-- | libs/cpu.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/libs/cpu.php b/libs/cpu.php new file mode 100644 index 0000000..e2743f9 --- /dev/null +++ b/libs/cpu.php @@ -0,0 +1,65 @@ +<?php + +// Number of cores +if (!($num_cores = shell_exec('/bin/grep -c ^processor /proc/cpuinfo'))) +{ + $num_cores = 'N.A'; +} + + +// CPU info +if (!($cpuinfo = shell_exec('cat /proc/cpuinfo'))) +{ + $model = 'N.A'; + $frequency = 'N.A'; + $cache = 'N.A'; + $bogomips = 'N.A'; +} +else +{ + $processors = preg_split('/\s?\n\s?\n/', trim($cpuinfo)); + + foreach ($processors as $processor) + { + $details = preg_split('/\n/', $processor, -1, PREG_SPLIT_NO_EMPTY); + + foreach ($details as $detail) + { + list($key, $value) = preg_split('/\s*:\s*/', trim($detail)); + + switch ($key) + { + case 'model name': + case 'cpu model': + case 'cpu': + $model = $value; + break; + + case 'cpu MHz': + case 'clock': + $frequency = $value.' MHz'; + break; + + case 'cache size': + case 'l2 cache': + $cache = $value; + break; + + case 'bogomips': + $bogomips = $value; + break; + } + } + } +} + + +$datas = array( + 'model' => $model, + 'num_cores' => $num_cores, + 'frequency' => $frequency, + 'cache' => $cache, + 'bogomips' => $bogomips, +); + +echo json_encode($datas);
\ No newline at end of file |