I want to use the select function on a group of sockets AND files like I would in C, but it seems the PHP select only takes sockets. Any idea how to convert file handler to socket, or another workaround?
Thanx
socket and file select
Moderator: General Moderators
Re: socket and file select
use stream_select(), it works both with socket streams and file streams (it would require you to use specialized stream_socket_* functions to create sockets though).
Re: socket and file select
Thanx! That worked well.
Another question about stream sockets: how would I know that the other side has disconnected?
Another question about stream sockets: how would I know that the other side has disconnected?
Re: socket and file select
Usually if the socket is selected, but has nothing to read, it's signals it's closed from the other side.MeLight wrote:Another question about stream sockets: how would I know that the other side has disconnected?
Something like this:
Code: Select all
if (select($read, $write, $except, null)) {
foreach ($read as $sock) {
$data = read($sock);
if (!$data) {
close($sock);
}
}
}
Re: socket and file select
ya figured it out eventually, checked if the string is empty. Thanx again 