1 function sys_windows() { 2 $objLocator = new COM("WbemScripting.SWbemLocator"); 3 $wmi = $objLocator->ConnectServer(); 4 $prop = $wmi->get("Win32_PnPEntity"); 5 //CPU 6 $cpuinfo = GetWMI($wmi,"Win32_Processor", array("Name","L2CacheSize","NumberOfCores")); 7 $res['CPU个数'] = $cpuinfo[0]['NumberOfCores']; 8 if (null == $res['CPU个数']) { 9 $res['CPU个数'] = 1; 10 } 11 for ($i=0;$i<$res['cpu']['num'];$i++){ 12 $res['CPU型号'] .= $cpuinfo[0]['Name']."<br>"; 13 $res['二级缓存'] .= $cpuinfo[0]['L2CacheSize']."<br>"; 14 } 15 // SYSINFO 16 $sysinfo = GetWMI($wmi,"Win32_OperatingSystem", array('LastBootUpTime','TotalVisibleMemorySize','FreePhysicalMemory','Caption','CSDVersion','SerialNumber','InstallDate')); 17 $res['操作系统版本'] = $sysinfo[0]['Caption']." ".$sysinfo[0]['CSDVersion']; 18 $res['SerialNumber'] = "{$sysinfo[0]['SerialNumber']} 于".date('Y年m月d日H:i:s',strtotime(substr($sysinfo[0]['InstallDate'],0,14)))."安装"; 19 //UPTIME 20 $res['最后重启时间'] = $sysinfo[0]['LastBootUpTime']; 21 22 $sys_ticks = 3600*8 + time() - strtotime(substr($res['最后重启时间'],0,14)); 23 $min = $sys_ticks / 60; 24 $hours = $min / 60; 25 $days = floor($hours / 24); 26 $hours = floor($hours - ($days * 24)); 27 $min = floor($min - ($days * 60 * 24) - ($hours * 60)); 28 if ($days !== 0) $ress['day'] = $days."天"; 29 if ($hours !== 0) $ress['hours'] .= $hours."小时"; 30 $res['最后重启时间'] = $ress['day'].$ress['hours'].$min."分钟"; 31 32 //MEMORY 33 $res['物理内存'] = $sysinfo[0]['TotalVisibleMemorySize']; 34 $res['剩余内存'] = $sysinfo[0]['FreePhysicalMemory']; 35 $res['已使用内存'] = $res['物理内存'] - $res['剩余内存']; 36 $res['使用率'] = round($res['已使用内存'] / $res['物理内存']*100,2); 37 38 $swapinfo = GetWMI($wmi,"Win32_PageFileUsage", array('AllocatedBaseSize','CurrentUsage')); 39 40 // TODO swp区获取 41 $res['交换分区'] = $swapinfo[0][AllocatedBaseSize]; 42 $res['已经使用'] = $swapinfo[0][CurrentUsage]; 43 $res['剩余内存'] = $res['swapTotal'] - $res['swapUsed']; 44 $res['使用率'] = (floatval($res['swapTotal'])!=0)?round($res['swapUsed']/$res['swapTotal']*100,2):0; 45 46 // LoadPercentage 47 $loadinfo = GetWMI($wmi,"Win32_Processor", array("LoadPercentage")); 48 $res['系统平均负载'] = $loadinfo[0]['LoadPercentage']; 49 50 return $res; 51 } 52 53 function GetWMI($wmi,$strClass, $strValue = array()) { 54 $arrData = array(); 55 56 $objWEBM = $wmi->Get($strClass); 57 $arrProp = $objWEBM->Properties_; 58 $arrWEBMCol = $objWEBM->Instances_(); 59 foreach($arrWEBMCol as $objItem) { 60 @reset($arrProp); 61 $arrInstance = array(); 62 foreach($arrProp as $propItem) { 63 eval("$value = $objItem->" . $propItem->Name . ";"); 64 if (empty($strValue)) { 65 $arrInstance[$propItem->Name] = trim($value); 66 } else { 67 if (in_array($propItem->Name, $strValue)) { 68 $arrInstance[$propItem->Name] = trim($value); 69 } 70 } 71 } 72 $arrData[] = $arrInstance; 73 } 74 return $arrData; 75 }