<?php
header("content-type:text/html;charset=utf-8"); // echo PHP_OS;exit;
// echo get_server_load();
var_dump(sys_getloadavg()); /*
$load = sys_getloadavg();
if ($load[0] > 80) {
header('HTTP/1.1 503 Too busy, try again later');
die('Server too busy. Please try again later.');
}
*/ // 建议最大负载不要超过3*N核,例如有16核(含8核超线程)则 16*3=48
function get_server_load() { if (stristr(PHP_OS, 'win')) { $wmi = new COM("Winmgmts://");
$server = $wmi->execquery("SELECT LoadPercentage FROM Win32_Processor"); $cpu_num = 0;
$load_total = 0; foreach($server as $cpu){
$cpu_num++;
$load_total += $cpu->loadpercentage;
} $load = round($load_total/$cpu_num); } else { $sys_load = sys_getloadavg();
$load = $sys_load[0]; } return (int) $load; }