1

I creating a web socket connection using ratchet php. I connected a client and then executed a query(it will take around 20 sec to execute the query) in the mean time I try to connect another client and I see that the web socket connection is in pending state(still trying to switch protocol). Later when the response has come for the initial request I see that the server prints 'new connection established' (have kept this statement in my onOpen function).

If react php works on same principle as NodeJs then even if the processing takes lot of time, shouldn't the connection get established?

Why is the web socket connection getting blocked because of the later execution part?

Aks
  • 183
  • 2
  • 11

1 Answers1

0

Well, that's not entirely accurate. Ratchet PHP and NodeJS aren't peas in a pod. They don't exactly work the same way.

What Ratchet PHP does, is utilize non-blocking I/O streams. This is everything from TCP/IP connections being made to your WS server, to any other IO connections facilitated by the framework.

However, you sated you're running a query, which I'm assuming was a database query? If you established the connection to this database yourself and not via Ratchet's non-blocking IO stream facility, then the database query is happening over a blocking TCP/UNIX socket. Which means, PHP has to sit there and wait for your dbms to respond to the query before it can continue executing any more code. So in the mean time your WebSocket server can't respond to any other requests, accept any other connections, or even run another line of code until that database system responds, because the TCP socket is in a WAIT state. It's just sitting around waiting for data to come down the pipe.

Sherif
  • 11,786
  • 3
  • 32
  • 57