Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 websockets

I'm trying to create a chat application using websockets and Symfony 2. Incoming messages for a given chatroom should be stored in a MySQL database and outgoing messages should be sent to all registrants of that chatroom. I was thinking about using something like this for the backend (with Symfony 2) https://github.com/GulDmitry/php-websocket-server

And this for the frontend http://socket.io/

I'm thinking all users should be added to some sort of global server data structure which specifies who to send messages to when chatrooms are updated. Is such a structure possible in PHP? It seems like it wouldn't be, so I'm not sure what is the best way to tackle this problem.

like image 545
CaptainStiggz Avatar asked May 15 '12 20:05

CaptainStiggz


1 Answers

Yes. The "server" would generally be a single php process the runs forever. You wouldnt want it running through your webserver, so you would start the socket server from the command line for example and just let it run. With that structure, you could just use an array to store all the users.

Eventually you might want more than one instance running. You can have multiple scripts communicate through memory, files, databases or other forms of IPC. So, the structure could be maintained outside any single socket server process. But, these are complications beyond the scope of your question.

like image 76
goat Avatar answered Sep 26 '22 06:09

goat