I've been searching over internet for last few days, a tutorial or script to show windows server load. I found this......

<?php
function get_server_load($windows = 0)
{
	$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 "";
		}
	}
	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 "";
		}
	}
}

$os = strtolower(PHP_OS);
if ($os !== 'winnt' AND $os !== 'win32')
{
	if (file_exists('/proc/loadavg'))
	{
		$data = file_get_contents('/proc/loadavg');
		$loads = explode(' ', $data);
		return $loads[0];
	}
}

$time_portions = explode(' ', microtime());
$start_time = $time_portions[1] . substr($time_portions[0], 1);

$time_portions = explode(' ', microtime());
$end_time = $time_portions[1] . substr($time_portions[0], 1);
$gen_time =  sprintf('%.3f', $ende_time - $start_time);
echo $gen_time;

?>

...... but I don't understand what it does and how it works. I mean all I see is
-1124939995.990, -1124940106.672, or sth else.

Is it possible to display the server load on windows like linux? Is there no way to show this with PHP?

    Write a Reply...