Skip to content
Advertisement

Multiple Socket Connection Using PHP

I have made a socket connection using php which is working perfectly below is the code for single socket but not working with multiple connections only accepts one connection at a time

JavaScript

I need a help to just make it work with multiple connection with clients. After that i need to make entry into database from client sent data.

Advertisement

Answer

You can’t listen many sockets using blocking socket connections at the same time. What you need is non-blocking socket connections with socket_select method instead of socket_accept.

My suggestion is to use some kind of PHP event-loop implementations (like reactphp).

Anyway, if you still want to implement it yourself, you can check the example of stream_select usage in reactphp/event-loop StreamSelectLoop implementation.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement