ホームページ >バックエンド開発 >PHPチュートリアル >php Windows システム検出プログラム_PHP チュートリアル
function do_command($commandName, $args) {
$buffer = "";
if (false === ($command = find_command($commandName))) return false;
if ($fp = @popen("$command $args", 'r')) {
その間 (!@feof($fp)){
$buffer .= @fgets($fp, 4096);
}
トリムを返す($buffer);
}
false を返します;
}
//windows系探测
関数 sys_windows() {
$objLocator = 新しい COM("WbemScripting.SWbemLocator");
$wmi = $objLocator->ConnectServer();
$prop = $wmi->get("Win32_PnPEntity");
//CPU
$cpuinfo = GetWMI($wmi,"Win32_Processor", array("名前","L2CacheSize","NumberOfCores"));
$res['cpu']['num'] = $cpuinfo[0]['NumberOfCores'];
if (null == $res['cpu']['num']) {
$res['cpu']['num'] = 1;
}
for ($i=0;$i
$res['cpu']['model'] .= $cpuinfo[0]['Name']."
";
$res['cpu']['cache'] .= $cpuinfo[0]['L2CacheSize']."
";
}
// SYSINFO
$sysinfo = GetWMI($wmi,"Win32_OperatingSystem", array('LastBootUpTime','TotalVisibleMemorySize','FreePhysicalMemory','Caption','CSDVersion','SerialNumber','InstallDate'));
$res['win_n'] = $sysinfo[0]['Caption']." ".$sysinfo[0]['CSSDVersion']." 配列号:{$sysinfo[ 0]['SerialNumber']} より".date('Y年m月d日H:i:s',strtotime(substr($sysinfo[0]['InstallDate'],0,14)))。安装";
//稼働時間
$res['uptime'] = $sysinfo[0]['LastBootUpTime'];
$sys_ticks = 3600*8 + time() - strtotime(substr($res['uptime'],0,14));
$min = $sys_ticks / 60;
$時間 = $分 / 60;
$days = フロア($hours / 24);
$hours = フロア($hours - ($days * 24));
$min = フロア($min - ($days * 60 * 24) - ($hours * 60));
if ($days !== 0) $res['uptime'] = $days."天";
if ($hours !== 0) $res['uptime'] .= $hours."小時間";
$res['uptime'] .= $min."分钟";
//メモリー
$res['memTotal'] = $sysinfo[0]['TotalVisibleMemorySize'];
$res['memFree'] = $sysinfo[0]['FreePhysicalMemory'];
$res['memused'] = $res['memTotal'] - $res['memFree'];
$res['memPercent'] =round($res['memused'] / $res['memTotal']*100,2);
$swapinfo = GetWMI($wmi,"Win32_PageFileUsage", array('AllocatedBaseSize','CurrentUsage'));
// TODO swp区获取
$res['swapTotal'] = $swapinfo[0][AllocatedBaseSize];
$res['swapused'] = $swapinfo[0][現在の使用量];
$res['swapFree'] = $res['swapTotal'] - $res['swapused'];
$res['swapPercent'] = (floatval($res['swapTotal'])!=0)?round($res['swapused']/$res['swapTotal']*100,2):0;
// LoadPercentage
$loadinfo = GetWMI($wmi,"Win32_Processor", array("LoadPercentage"));
$res['loadAvg'] = $loadinfo[0]['LoadPercentage'];
$res を返す;
}
関数 GetWMI($wmi,$strClass, $strValue = array()) {
$arrData = array();
$objWEBM = $wmi->Get($strClass);
$arrProp = $objWEBM->プロパティ_;
$arrWEBMCol = $objWEBM->インスタンス_();
foreach($arrWEBMol as $objItem) {
@reset($arrProp);
$arrInstance = array();
foreach($arrProp as $propItem) {
eval("$value = $objItem->" . $propItem->Name . ";");
if (empty($strValue)) {
$arrInstance[$propItem->名前] = トリム($値);
} その他 {
if (in_array($propItem->Name, $strValue)) {
$arrInstance[$propItem->名前] = トリム($値);
}
}
}
$arrData[] = $arrInstance;
}
$arrData を返す;
}