| 一个CPU和内存使用的获取函数 function amh_module_init_cpu() { $data = array(); $cpuinfo = file_get_contents('/proc/cpuinfo'); $physical_list = array(); $physical_sum = 0; $cores_sum = 0; $siblings_sum = 0; preg_match("/model name\s*:(.*)/", $cpuinfo, $name); preg_match("/vendor_id\s*:(.*)/", $cpuinfo, $vendor); preg_match("/cpu family\s*:(.*)/", $cpuinfo, $family); preg_match("/cpu MHz\s*:(.*)/", $cpuinfo, $MHz); preg_match("/cache size\s*:(.*)/", $cpuinfo, $cache); $name = isset($name[1]) ? $name[1] : 'No'; $vendor = isset($vendor[1]) ? $vendor[1] : 'No'; $family = isset($family[1]) ? $family[1] : 'No'; $MHz = isset($MHz[1]) ? number_format($MHz[1]/1000, 2) : 'No'; $cache = isset($cache[1]) ? $cache[1] : 'No'; $p_list = explode("\nprocessor", $cpuinfo); foreach ($p_list as $key=>$val) { preg_match("/physical id\s*:(.*)/", $val, $physical); preg_match("/cpu cores\s*:(.*)/", $val, $cores); preg_match("/siblings\s*:(.*)/", $val, $siblings); if (isset($physical[1])) { if (!in_array($physical[1], $physical_list)) { $physical_sum += 1; if (isset($cores[1])) $cores_sum += $cores[1]; if (isset($siblings[1])) $siblings_sum += $siblings[1]; } $physical_list[] = $physical[1];... 2019年 12月 20日 |