Most of the examples I'm looking at with Ratchet are for chat services, and I'm currently building an application where the user logs in and receives notifications from the server based on their user ID.
I have the basic tutorials working, however I'm struggling to understand a few points:
When the onOpen()
method is called, I set the $conn
object into an array like so:
$this->clients[$conn->resourceId]['conn'] = $conn;
In my Javascript, within the onopen
function I also send a JSON payload with the send
function. My server pics this up and stores it like so, in the onMessage
method:
$this->clients[$conn->resourceId]['json'] = $json;
So now I have my connected users stored in an array, how do I send a message to a specific user? I've looked into onSubscribe
and the broadcast
to no avail, but don't really understand what the WampServerInterface
is supposed to be used for?
Since my own class is a running script, I obviously can't create a new instance of it anywhere else. As my application will be sending user specific updates I need some sort of way to do this following:
Grab the currently connected users using another script, process these somewhere and return any updates they might have, every 60 seconds. Now although this might sound like polling, it would only be one connection doing this and so wouldn't be intensive on the server - at least that's what I think. So how can I interact my running server script with other "static" PHP scripts elsewhere?
Thanks