Private and Group Conversations Using Ratchet and WebSockets on PHP

advertisements

I aim to make an chat app with an option for private and group chats. I'm more used to using Ratchet and WebSockets with PHP, rather than using node.js, being that people told me that would be the best.

Though I've only seen examples of WebSockets on the context of global chats.

My approach is to use the WebSocket id and store it in the Database, for when people request to chat with a certain person or with people from a certain group, I would give the server those id's and it would send to only those people

Would that be the right way? Is there any better approach to this?


When you create a socket you create a handle to a resource; you can't store the handle to the resource in a database.

What you need to do is create one-on-one client-server socket connections for each user, then distribute the chats through those connections. If a user disconnects, the socket is connection is lost and you can't send messages so you have to store in a database and then flush out when they do connect.