Calling socket_select() multiple times in one script?

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

Calling socket_select() multiple times in one script?

Post by kaoskorruption »

I understand that socket_select() does not return until it detects changes the the specified socket.
Is it possible to have it check for changes in two separate sockets at once, and somehow tell which of the two sockets was the one that changed?

If not, is there a way to listen on two different sockets in the same script and handle the incoming data?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Calling socket_select() multiple times in one script?

Post by volka »

kaoskorruption wrote:Is it possible to have it check for changes in two separate sockets at once, and somehow tell which of the two sockets was the one that changed?
Yes, that's why the parameters are arrays.

please read http://de2.php.net/manual/en/function.socket-select.php
kaoskorruption
Forum Commoner
Posts: 28
Joined: Tue Jul 18, 2006 2:09 pm

Post by kaoskorruption »

The other arrays are for writing and exeptions though. What I need is to see if I can get 2 read arrays to work.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please read the manual page carefully.
kaoskorruption
Forum Commoner
Posts: 28
Joined: Tue Jul 18, 2006 2:09 pm

Post by kaoskorruption »

I've read the article extremely thouroughly. It doesn't say anything about checking a socket for reading for more than one array.

I guess it's possible to to copy two arrays into one array, so that it checks the new array, but theres a problem with that. When socket_select() returns, you won't know which of the arrays changed.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

kaoskorruption wrote:Is it possible to have it check for changes in two separate sockets at once, and somehow tell which of the two sockets was the one that changed?
So what do you want?
Check to arrays of sockets or two sockets?
kaoskorruption
Forum Commoner
Posts: 28
Joined: Tue Jul 18, 2006 2:09 pm

Post by kaoskorruption »

Sorry I meant two arrays of sockets. I was thinking two sockets because it would have have two listening sockets.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Why would there be two arrays of "read" sockets in a single, single-threaded script? Really seems like a desgin fault to me.
Post Reply