• 0

Server Load


Question

-=[Blueshadowz]=-

I need a little script written php showing the server load or page load. Is there any good once out there?

Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0
Tim Dorr

<?php print `uptime`; ?>

Link to post
Share on other sites
  • 0
Blackout

Erm...correct me if I'm wrong but I think that displays the server uptime? The server load is the server's CPU load.

Link to post
Share on other sites
  • 0
roosevelt

It also displays server's cpu load, like "load average:"

Link to post
Share on other sites
  • 0
matt95110

Well I don't know a whole lot on putting Server Load onto one of my pages, but if you are trying to put the execution time on, there are plenty of good tutorials out there on how to do it. Actually I think Dessimat0r has one on here somewhere, search for it.

And quit saying "once", its "ones".

Link to post
Share on other sites
  • 0
Ricky Baby

Server Load

 $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];
 	 }
  }

timer - start of the page:

//start timing
$time_portions = explode(' ', microtime());

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

to show the time do

$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;

Link to post
Share on other sites
  • 0
PRSBOY

sorry to bump this really old thread, but is there any way to get server loads on a windows server?

Link to post
Share on other sites
  • 0
+theblazingangel

in the first line you can change '$windows = false' to '$windows = true' to get it to do it on windows. note that on windows it'll add a whole second to page load times!

function getServerLoad($windows = false)
{
	$os = strtolower(PHP_OS);
	if (strpos($os, "win") === false) {
		if (file_exists("/proc/loadavg")) {
			$data = file_get_contents("/proc/loadavg");
			$load = explode(' ', $data);
			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-&gt;InstancesOf("Win32_Processor");

	 		$cpuload = 0;
	 		$i = 0;

			if(version_compare('4.50.0', PHP_VERSION) == 1) {
				// PHP 4
				while ($cpu = $cpus-&gt;Next()) {
					$cpuload += $cpu-&gt;LoadPercentage;
					$i++;
				}

			} else {

				// PHP 5
				foreach ( $cpus as $cpu ) {
					$cpuload += $cpu-&gt;LoadPercentage;
					$i++;
				}
			}

	 		$cpuload = round($cpuload / $i, 2);
	 		return "$cpuload%";

		} else {

			return false;
		}
	}
}

Link to post
Share on other sites
  • 0
PRSBOY

so it does, thats lame.

thanks for the code anyways!

Link to post
Share on other sites
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.