This linux system parameter detection function calculates how much of your current machine's CPU is, how much memory is used, when it runs, and when it is updated.
LINUX system parameter detection including CPU, time, memory, etc.
function Sys_linux ()
{
Cpu
if (false = = = ($str = @file ("/proc/cpuinfo"))) return false;
$str = Implode ("", $str);
@preg_match_all ("/models+names{0,}:+s{0,} ([WS) (.] +) [rn]+/, $str, $model);
@preg_match_all ("/cpus+mhzs{0,}:+s{0,} ([D.] +) [rn]+/, $str, $mhz);
@preg_match_all ("/caches+sizes{0,}:+s{0,} ([D.] +s{0,}[a-z]+[rn]+)/", $str, $cache);
if (False!== Is_array ($model [1]))
{
$res [' CPU '] [' num '] = sizeof ($model [1]);
for ($i = 0; $i < $res [' CPU '] [' num ']; $i + +)
{
$res [' CPU '] [' detail '] [] = ' type: '. $model [1][$i]. "Cache:". $cache [1][$i];
}
if (False!== Is_array ($res [' CPU '] [' detail ']) $res [' CPU '] [' detail '] = implode ("
", $res [' CPU '] [' detail ']);
}
UPTIME
if (false = = = ($str = @file ("/proc/uptime"))) return false;
$str = Explode ("", Implode ("", $str));
$str = Trim ($str [0]);
$min = $STR/60;
$hours = $min/60;
$days = Floor ($hours/24);
$hours = Floor ($hours-($days * 24));
$min = Floor ($min-($days *)-($hours * 60));
if ($days!== 0) $res [' uptime '] = $days. " Days ";
if ($hours!== 0) $res [' uptime ']. = $hours. " Hours ";
$res [' uptime ']. = $min. " Minutes ";
MEMORY
if (false = = = ($str = @file ("/proc/meminfo"))) return false;
$str = Implode ("", $str);
Preg_match_all ("/memtotals{0,}:+s{0,} ([D.] +).+? Memfrees{0,}:+s{0,} ([D.] +).+? Swaptotals{0,}:+s{0,} ([D.] +).+? Swapfrees{0,}:+s{0,} ([D.] +)/S ", $str, $buf);
$res [' memtotal '] = round ($buf [1][0]/1024, 2);
$res [' memfree '] = round ($buf [2][0]/1024, 2);
$res [' memused '] = ($res [' memtotal ']-$res [' memfree ']);
$res [' mempercent '] = (floatval ($res [' memtotal '])!=0)? Round ($res [' memused ']/$res [' Memtotal ']*100,2]: 0;
$res [' swaptotal '] = round ($buf [3][0]/1024, 2);
$res [' swapfree '] = round ($buf [4][0]/1024, 2);
$res [' swapused '] = ($res [' swaptotal ']-$res [' swapfree ']);
$res [' swappercent '] = (floatval ($res [' swaptotal '])!=0)? Round ($res [' swapused ']/$res [' Swaptotal ']*100,2]: 0;
LOAD AVG
if (false = = = ($str = @file ("/proc/loadavg"))) return false;
$str = Explode ("", Implode ("", $str));
$str = Array_chunk ($str, 3);
$res [' loadavg '] = Implode ("", $str [0]);
return $res;
}
Calling methods
Sys_linux ();
/*
This modelLinux system parameter detection function, you can calculate how much of your current machine is CPU, how much memory is used, how long it is running, and what time it is updated
*/
http://www.bkjia.com/PHPjc/444943.html www.bkjia.com true http://www.bkjia.com/PHPjc/444943.html techarticle This linux system parameter detection function, you can calculate the current machine's CPU, how much memory used, run time and update time LINUX system parameter detection includes CPU, time ...