[PHP] Display Server Load

<?php 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;
 if(version_compare('4.50.0', PHP_VERSION) == 1) {
 // PHP 4
 while ($cpu = $cpus->Next()) {
 $cpuload += $cpu->LoadPercentage;
 $i++;
 }
 } else {
 // PHP 5
 foreach($cpus as $cpu) {
 $cpuload += $cpu->LoadPercentage;
 $i++;
 }
 }
 $cpuload = round($cpuload / $i, 2);
 return "$cpuload%";
 } else {
 return false;
 }
 }
} ?>

Popularity: unranked [?]


  1. No comments yet.

  1. No trackbacks yet.

Chọn kiểu gõ: Tự động TELEX VNI Tắt

Bad Behavior has blocked 52 access attempts in the last 7 days.