LINUX system parameter detection includes cpu, time, memory, and so on. This linux system parameter detection function calculates the cpu usage, memory usage, and running time of your current machine. LINUX system parameter detection includes cpu, the linux system parameter detection function calculates the cpu usage, memory usage, running time, and update time of your current machine.
LINUX system parameter detection includes 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 * 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 = ($ 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]/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]/0, 1024, 2 );
$ Res ['swapfree'] = round ($ buf [4] [0]/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;
}
// Call method
Sys_linux ();
/*
ThisLinux system parameter detection functionsTo calculate the cpu usage, memory usage, running time, and update time of your current machine.
*/
Kernel LINUX system parameter detection includes cpu, time...