Help with socket_select

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kaoskorruption
Forum Commoner
Posts: 28
Joined: Tue Jul 18, 2006 2:09 pm

Help with socket_select

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
kaoskorruption
Forum Commoner
Posts: 28
Joined: Tue Jul 18, 2006 2:09 pm

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
kaoskorruption
Forum Commoner
Posts: 28
Joined: Tue Jul 18, 2006 2:09 pm

Post by kaoskorruption »

Ohhhhhhhhhhhh that explains alot. Thanks again!
Post Reply