I have a homebrew PHP TCP chat server, but it doesn't have a way to detect remote disconnects.
I would be grateful if someone knew a way to just take a stream_socket_server() and spit out everything connected to it.
Then you could run a loop like this, in psuedocode:
$main_socket=stream_socket_server("tcp://",....)
//Do Something.... say, wait for a connection (with stream_socket_accept())?
for (each CONNECTION in $main_socket)
{
//Do something with or to that connection
}
//Loop back... if you need to say, wait for another connection
Alternatively, could I check if a variable created with $stream_socket_accept() is presently connected.
This project is bust until I figure this out. I'd be grateful to anyone who could help me out on this one!
The correct way of knowing if the remote host has disconnected is to test for a false socket_read()
, as far as I know.
Have a look at this question; PHP - Detecting remote host disconnection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With