FreeBSD system parameters detect cpu and memory. This is a php System parameter test. it can detect FreeBSDcpu, memory, update time, and running time. FreeBSD system parameter detection cpu, memory * This is a php Tutorial system this is a php System parameter detection, it can detect FreeBSD cpu, memory, update time, run time and so on.
FreeBSD system parameter detection cpu, memory
/*
This is a php System parameter test. it can detect FreeBSD cpu, memory, update time, and running time.
*/
// Obtain the parameter value FreeBSD
Function get_key ($ keyName)
{
Return do_command ('sysctl ', "-n $ keyName ");
}
// Determine the execution file location FreeBSD
Function find_command ($ commandName)
{
$ Path = array ('/bin','/sbin', '/usr/bin','/usr/sbin', '/usr/local/bin ', '/usr/local/sbin ');
Foreach ($ path as $ p)
{
If (@ is_executable ("$ p/$ commandName") return "$ p/$ commandName ";
}
Return false;
}
Function sys_freebsd ()
{
// CPU
If (false ===( $ res ['CPU '] ['num'] = get_key ("hw. ncpu") return false;
$ Res ['CPU'] ['detail'] = get_key ("hw. model ");
// LOAD AVG
If (false = ($ res ['loadavg'] = get_key ("vm. loadAvg") return false;
$ Res ['loadavg'] = str_replace ("{", "", $ res ['loadavg']);
$ Res ['loadavg'] = str_replace ("}", "", $ res ['loadavg']);
// UPTIME
If (false = ($ buf = get_key ("kern. boottime") return false;
$ Buf = explode ('', $ buf );
$ Sys_ticks = time ()-intval ($ buf [3]);
$ Min = $ sys_ticks/60;
$ Hours = $ min/60;
$ Days = floor ($ hours/24 );
$ Hours = floor ($ hours-($ days * 24 ));
$ Min = floor ($ min-($ days * 60*24)-($ hours * 60 ));
If ($ days! = 0) $ res ['uptime'] = $ days. "day ";
If ($ hours! = 0) $ res ['uptime']. = $ hours. "hour ";
$ Res ['uptime']. = $ min. "minute ";
// MEMORY
If (false = ($ buf = get_key ("hw. physmem") return false;
$ Res ['memtotal'] = round ($ buf/1024/1024, 2 );
$ Buf = explode ("n", do_command ("vmstat ",""));
$ Buf = explode ("", trim ($ buf [2]);
$ Res ['memfree'] = round ($ buf [5]/1024, 2 );
$ Res ['memused'] = ($ res ['memtotal']-$ res ['memfree']);
$ Res ['mempercent '] = (floatval ($ res ['memtotal'])! = 0 )? Round ($ res ['memused']/$ res ['memtotal'] * 100,2): 0;
$ Buf = explode ("n", do_command ("swapinfo", "-k "));
$ Buf = $ buf [1];
Preg_match_all ("/([0-9] +) s + ([0-9] +) s + ([0-9] +)/", $ buf, $ bufArr );
$ Res ['swaptotal'] = round ($ bufArr [1] [0]/1024, 2 );
$ Res ['swapused'] = round ($ bufArr [2] [0]/1024, 2 );
$ Res ['swapfree'] = round ($ bufArr [3] [0]/1024, 2 );
$ Res ['swappercent '] = (floatval ($ res ['swaptotal'])! = 0 )? Round ($ res ['swapused']/$ res ['swaptotal'] * 100,2): 0;
Return $ res;
}
// Usage of probe
Sys_freebsd ();
Reset cpu, memory, update time, and running time. FreeBSD system parameter detects cpu, memory/* This is a php Tutorial system...