0

I have a PHP script:

$loads = sys_getloadavg();
$core_nums = trim(shell_exec("grep -P '^processor' /proc/cpuinfo|wc -l"));
$load = round($loads[0]/($core_nums)*100, 10);

I running this script each second using AJAX and setInterval for building CPU Load chart. But result of this PHP script updates only after 3 or more calls:

cpu graph

How can I get new data each second???

Danibix
  • 235
  • 9
  • 18
  • ajax is slow. every ajax request is a full-blown http roundtrip to/from the server. You'd be better off using a websocket and PUSHING per-second data to your client. – Marc B Sep 08 '16 at 15:04
  • 3
    You could probably reduce the load on the CPU by 50% by not looking at the CPU load – RiggsFolly Sep 08 '16 at 15:04
  • No! Problem isn't from AJAX. I can reflesh the page with this PHP and I will still get the same result. – John Kindle Sep 08 '16 at 15:07
  • 1
    Have you considered a real monitoring tool, such as statsd with system info collection (like DataDog does)? – ssube Sep 08 '16 at 15:07
  • You may consider checking this [answer](http://stackoverflow.com/a/18152413/6381711). – nyedidikeke Sep 08 '16 at 21:55

0 Answers0