本文整理汇总了PHP中COM::InstancesOf方法的典型用法代码示例。如果您正苦于以下问题:PHP COM::InstancesOf方法的具体用法?PHP COM::InstancesOf怎么用?PHP COM::InstancesOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COM
的用法示例。
在下文中一共展示了COM::InstancesOf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getServerLoad
/**
* Get server load ... if linux, returns all three averages, if windows, returns
* average load for all CPU cores
*
* @return string|null
*/
public static function getServerLoad()
{
if (function_exists('sys_getloadavg')) {
$a = sys_getloadavg();
foreach ($a as $k => $v) {
$a[$k] = round($v, 2);
}
return implode(', ', $a);
} else {
$os = strtolower(PHP_OS);
if (strpos($os, 'win') === false) {
if (@file_exists('/proc/loadavg') && @is_readable('/proc/loadavg')) {
$load = file_get_contents('/proc/loadavg');
$load = explode(' ', $load);
return implode(',', $load);
} else {
if (function_exists('shell_exec')) {
$load = @shell_exec('uptime');
$load = split('load average' . (PHP_OS == 'Darwin' ? 's' : '') . ':', $load);
return implode(',', $load);
//return $load[count($load)-1];
} else {
return null;
}
}
} else {
if (class_exists('COM')) {
$wmi = new COM("WinMgmts:\\\\.");
$cpus = $wmi->InstancesOf('Win32_Processor');
$cpuload = 0;
$i = 0;
while ($cpu = $cpus->Next()) {
$cpuload += $cpu->LoadPercentage;
$i++;
}
$cpuload = round($cpuload / $i, 2);
return $cpuload . '%';
}
}
}
return null;
}
示例2: get_server_load
function get_server_load($windows = false) {
$os = strtolower(PHP_OS);
if(strpos($os, "win") === false) {
if(file_exists("/proc/loadavg")) {
$load = file_get_contents("/proc/loadavg");
$load = explode(' ', $load);
return $load[0];
}
elseif(function_exists("shell_exec")) {
$load = explode(' ', `uptime`);
return $load[count($load)-1];
}
else {
return false;
}
}
elseif($windows) {
if(class_exists("COM")) {
$wmi = new COM("WinMgmts:\\\\.");
$cpus = $wmi->InstancesOf("Win32_Processor");
$cpuload = 0;
$i = 0;
while ($cpu = $cpus->Next()) {
$cpuload += $cpu->LoadPercentage;
$i++;
}
$cpuload = round($cpuload / $i, 2);
return "$cpuload%";
}
else {
return false;
}
}
}
示例3: strtolower
function get_server_load($windows = 0)
{
$serverload = "n/a";
if (!($serverload = getCache("pool_load"))) {
$numberOfCores = 8;
$avgLoad = 0;
$os = strtolower(PHP_OS);
if (strpos($os, "win") === false) {
if (file_exists("http://" . $poolname . "/loadavg.html")) {
$load = file_get_contents("http://" . $poolname . "/loadavg.html");
$load = explode(' ', $load);
$avgLoad = $load[0];
} elseif (function_exists("shell_exec")) {
$load = explode(' ', `uptime`);
$avgLoad = $load[count($load) - 1];
}
//This may need to be adjusted depending on your system. This is assuming a dual core setup.
if ($avgLoad > 1.9 * $numberOfCores) {
$serverload = "critical";
} else {
if ($avgLoad > 1.5 * $numberOfCores) {
$serverload = "high";
} else {
if ($avgLoad > 0.5 * $numberOfCores) {
$serverload = "mid";
} else {
if ($avgLoad > 0 * $numberOfCores) {
$serverload = "low";
}
}
}
}
} elseif ($windows) {
if (class_exists("COM")) {
$wmi = new COM("WinMgmts:\\\\.");
$cpus = $wmi->InstancesOf("Win32_Processor");
$cpuload = 0;
$i = 0;
while ($cpu = $cpus->Next()) {
$cpuload += $cpu->LoadPercentage;
$i++;
}
$cpuload = round($cpuload / $i, 2);
$avgLoad = $cpuload;
}
if ($avgLoad > 90) {
$serverload = "critical";
} else {
if ($avgLoad > 66) {
$serverload = "high";
} else {
if ($avgLoad > 33) {
$serverload = "mid";
} else {
if ($avgLoad > 0) {
$serverload = "low";
}
}
}
}
}
if ($serverload != "n/a") {
}
setCache("pool_load", $serverload, 60);
}
return $serverload;
}
示例4: get_server_load
function get_server_load($windows = 0)
{
if (class_exists("COM")) {
$wmi = new COM("WinMgmts:\\\\.");
$cpus = $wmi->InstancesOf("Win32_Processor");
$i = 1;
// Use the while loop on PHP 4 and foreach on PHP 5
//while ($cpu = $cpus->Next()) {
foreach ($cpus as $cpu) {
$cpu_stats = 0;
$cpu_stats += $cpu->LoadPercentage;
$i++;
}
return round($cpu_stats / 2);
// remove /2 for single processor systems
}
}
示例5: COM
<?php
$wmi = new COM("Winmgmts://");
$cpus = $wmi->InstancesOf("Win32_Processor");
$os = $wmi->InstancesOf("Win32_OperatingSystem");
foreach ($os as $os) {
$os = "{$os->Caption} {$os->CSDVersion}";
}
$os = preg_replace("/(Microsoft|\\(R\\)|, \\w+ Edition)/", "", $os);
$os = str_replace("Service Pack ", "SP", $os);
$system = $wmi->InstancesOf("Win32_ComputerSystem");
$ram = $wmi->InstancesOf("Win32_LogicalMemoryConfiguration");
foreach ($ram as $ram) {
$ramtotal = $ram->TotalPhysicalMemory * 1024;
}
$ram = $wmi->InstancesOf("Win32_PerfRawData_PerfOS_Memory");
foreach ($ram as $ram) {
}
$ramused = $ramtotal - $ram->AvailableBytes;
$ramused = mksize($ramused);
$ramtotal = mksize($ramtotal);
$uptime = $wmi->InstancesOf("Win32_PerfFormattedData_PerfOS_System");
foreach ($uptime as $uptime) {
}
$uptime = mkprettytime2($uptime->SystemUpTime);
foreach ($cpus as $cpu) {
$cpus1[] = $cpu->LoadPercentage;
$totalusage += $cpu->LoadPercentage;
}
$cpucount = count($cpus1);
$totalusage = round($totalusage / $cpucount, 2);