0

End Goal: We want our CPU meter on our website to update live as we retrieve CPU % from C++ client via sockets.

My friend and I didn't exactly know which to use to accomplish this task, have AJAX or Sockets via PHP to request the CPU usage from my C++ application and update the meter on the website with whatever value is received from the client.

Is there any other way to update the website in real time after it's been already loaded other than AJAX? If not, should the website request the information from the client via sockets and then store it to a variable and pass to AJAX to update the element?

Your help is highly appreciated :) We are working on a energy efficiency project for school. (I'm in school for C++, and he is in for web development)

  • [link](http://stackoverflow.com/questions/8051516/how-to-establish-a-tcp-socket-connection-from-a-web-browser-client-side) is relevant –  Jul 22 '16 at 04:10

1 Answers1

0

BROWSER [with ajax] --> Webserver [PHP script that calls the C++ Application]

[ Browser]   [apache that hosts your php app]   [C++] 
    |           |                                 |
    |---(1)---->|----------(2)------------------->|
    |<----------|<--------------------------------|

(1): ajax calls periodic with setIntervall() in javascript

(2): exec() function in php that calls a system script that is called whenever you receive an ajax call .. whatever the result of the exec command can be wrapped in a json format and sent back to the browser.

*: the other way to do is more advanced using websockets: Using rabbitmq (message brocker) and socketio server + socketio javascript client .. but it is "over engineered" for your use case, if you are interested to know more about I will be happy to explain in details.

Sorry i tried to make it clear .. i hope it helps !

M. Gara
  • 1,023
  • 2
  • 14
  • 27