function Do_command ($commandName, $args) {
$buffer = "";
if (false = = = ($command = Find_command ($commandName))) return false;
if ($fp = @popen ("$command $args", ' R ')) {
while (! @feof ($fp)) {
$buffer. = @fgets ($fp, 4096);
}
Return trim ($buffer);
}
return false;
}
Windows system probing
function Sys_windows () {
$objLocator = new COM ("WbemScripting.SWbemLocator");
$WMI = $objLocator->connectserver ();
$prop = $wmi->get ("win32_pnpentity");
Cpu
$cpuinfo = Getwmi ($wmi, "Win32_Processor", Array ("Name", "L2cachesize", "numberofcores"));
$res [' CPU '] [' num '] = $cpuinfo [0][' numberofcores '];
if (null = = $res [' CPU '] [' num ']) {
$res [' CPU '] [' num '] = 1;
}
for ($i =0; $i < $res [' CPU '] [' num ']; $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][' CSDVersion ']."Serial Number: {$sysinfo [0][' serialnumber '} ' on '. Date (' Y ' m ' d ' h:i:s ', Strtotime (substr ($sysinfo [0][' installdate '],0,14 ')). " Installation ";
UPTIME
$res [' uptime '] = $sysinfo [0][' LastBootUpTime '];
$sys _ticks = 3600*8 + Time ()-Strtotime (substr ($res [' uptime '],0,14)];
$min = $sys _ticks/60;
$hours = $min/60;
$days = Floor ($hours/24);
$hours = Floor ($hours-($days * 24));
$min = Floor ($min-($days *)-($hours * 60));
if ($days!== 0) $res [' uptime '] = $days. " Days ";
if ($hours!== 0) $res [' uptime ']. = $hours. " Hours ";
$res [' uptime ']. = $min. " Minutes ";
MEMORY
$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 Zone get
$res [' swaptotal '] = $swapinfo [0][allocatedbasesize];
$res [' swapused '] = $swapinfo [0][currentusage];
$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 '];
return $res;
}
function Getwmi ($WMI, $strClass, $strValue = Array ()) {
$arrData = Array ();
$objWEBM = $wmi->get ($strClass);
$arrProp = $objWEBM->properties_;
$arrWEBMCol = $objWEBM->instances_ ();
foreach ($arrWEBMCol as $objItem) {
@reset ($arrProp);
$arrInstance = Array ();
foreach ($arrProp as $propItem) {
Eval ("$value = $objItem." $propItem->name. ";");
if (empty ($strValue)) {
$arrInstance [$propItem->name] = Trim ($value);
} else {
if (In_array ($propItem->name, $strValue)) {
$arrInstance [$propItem->name] = Trim ($value);
}
}
}
$arrData [] = $arrInstance;
}
return $arrData;
}
http://www.bkjia.com/PHPjc/632007.html www.bkjia.com true http://www.bkjia.com/PHPjc/632007.html techarticle function Do_command ($commandName, $args) {$buffer =; if (false = = = ($command = Find_command ($commandName))) return F Alse; if ($fp = @popen ($command $args, ' R ')) {while (! @feof ($ ...