Page 1 of 1

Help with socket_select

Posted: Tue Jul 18, 2006 2:15 pm
by kaoskorruption
Can someone explain exactly what socket_select does and what purpose it serves?

I've read the info on it at php.net and looked at the examples/tutorials. Bascially I understand that it accepts an array of sockets, and it knows when something about them changes. But what I don't understand is what exactly it does when it detects a change.

Thanks very much,
-Chris

Posted: Tue Jul 18, 2006 2:23 pm
by Weirdan
PHP Manual wrote: socket_select() accepts arrays of sockets and waits for them to change status
It pauses your script until an event occures on watched sockets. Once it returns, you know for sure that something has happened to these sockets you passed to it.

Posted: Tue Jul 18, 2006 2:51 pm
by kaoskorruption
Ok thanks, that helps alot. One more question:
On exit, the arrays are modified to indicate which socket resource actually changed status.
What exactly does that mean?

Posted: Tue Jul 18, 2006 2:57 pm
by Weirdan
Simple example:

Code: Select all

$read_sockets = array($socket1, $socket2);
socket_select($read_sockets, null, null, null);
// once you hit this line, you would have in $read_sockets only those socket that are ready to be read from.

Posted: Tue Jul 18, 2006 3:59 pm
by kaoskorruption
Ohhhhhhhhhhhh that explains alot. Thanks again!