that would be done with Ajax or WEbSockets.
WebSocket works by opening a connection channel between the server and users.
you can find some websocket Examples Here:
http://www.websocket.org/demos.html
1
solved Send data to JS when PHP is told to do so