Page 1 of 1

Calling socket_select() multiple times in one script?

Posted: Mon Jul 31, 2006 8:01 pm
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?

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

Posted: Tue Aug 01, 2006 5:31 am
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

Posted: Tue Aug 01, 2006 8:47 am
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.

Posted: Tue Aug 01, 2006 9:17 am
by volka
Please read the manual page carefully.

Posted: Tue Aug 01, 2006 1:02 pm
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.

Posted: Tue Aug 01, 2006 1:44 pm
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?

Posted: Wed Aug 02, 2006 12:09 am
by kaoskorruption
Sorry I meant two arrays of sockets. I was thinking two sockets because it would have have two listening sockets.

Posted: Wed Aug 02, 2006 3:07 am
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.