I need to establish connection between a client and a server via PHP websocket.
The server will need to keeps checking with an external API for new messages and send them to the client.
I would like to understand the concept so I can code it. I have some questions to help me wrap it around my head.
The Client Side
Do I keep making calls to the server via the websocket every second using javascript's setInterval()
function or do I only make one call? How does the client know that the server have new messages?
The Server Side Do I create a script the runs an infinite loop to keep checking with the API and echo the results?
Websocket How does the websocket know which connection a message belong to?
I am not sure if it matter but I am going to use Ratchet for creating the websocket