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???

5
  • 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. Commented Sep 8, 2016 at 15:04
  • 3
    You could probably reduce the load on the CPU by 50% by not looking at the CPU load Commented Sep 8, 2016 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. Commented Sep 8, 2016 at 15:07
  • 1
    Have you considered a real monitoring tool, such as statsd with system info collection (like DataDog does)? Commented Sep 8, 2016 at 15:07
  • You may consider checking this answer. Commented Sep 8, 2016 at 21:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.