<?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] >) { header (' http/1.1 503 Too Busy, try again later ') ; Die (' Server too busy. Please try again later. ');} *///recommends that the maximum load not exceed the 3*n core, such as 16 cores (with 8 core Hyper-threading), then 16*3=48function 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;}
PHP Server load Judgment