paragi / PHP-websocket-client

142 stars 61 forks source link

[Question] check connection status #12

Closed cabelito closed 3 years ago

cabelito commented 4 years ago

Hi Paragi, Really good class for PHP. I started using it, however I only use this class to send notifications (one-way) from my server to another websocket server. The only problem I am facing right now is that if for some reason the connection has beed dropped I have to restart my PHP server script because it has to reconnect to the server( websocket) again. Is there a way to check if connection is alive or it was dropped , so I can reconnect using websocket_open ?

My scenario is: I open new connection with websocket_open and then I send notifications using websocket_write

but if in the meantime connection is dropped, my websocket_write function shows ERROR messages that it was unable to send messages? I want to check the connection before writing

cabelito commented 3 years ago

Hi all , Looks like I found a solution using feof($sp) returns true if connection was dropped so: if (feof($sp) === true) { reconnect } else { we are still connected }

paragi commented 3 years ago

Great. I didn't even have to do anything :) Please feel free to add your solution to the REAMDE.md