Re: [PHP4BETA] select() Design Notes
| From: | Colin Putney | Date: | Mon, 06 Dec 1999 20:29:41 +0000 |
| Subject: | Re: [PHP4BETA] select() Design Notes | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-7550@lists.php.net to get a copy of this message | ||
-- Evan Klinger <evan715@sirius.com> wrote:
> As I have it now, it works like Thies' original posting
> (select($timeout,$rfd[,$wfd][,$efd]) where $?fd can be an array of fd
> resources or a single fd resource). Since I see no easy way for
> select() to return whether each passed $?fd is set, fd_isset() can be
> used to check the status of a $?fd.
>
> How this works:
> select() extracts each fd in $?fd if it is an array. Each of these
> fd's is then FD_SET() into their appropriate fd_set (read, write,
> except). Because fd_isset() needs access to the fd_set and we don't
> want globals, select() registers the fd_sets with a key so that it is
> constant and can be fetched in fd_isset().
> fd_isset($fd,"read"|"write"|"except") is passed the $fd that you
> want
> to check and a string identifying the set. The string is needed
> because the passed $fd could be in more than one set.
This seems ideal to me, from the PHP side of things. If it works
without globals and other such Bad Things, I say go with it. One
question though: will select mind if the array indicies are not
integers? I'd like to do something like this (as soon as we upgrade to
PHP4):
<?php
$rfd["php"] = fsockopen("www.php.net",80);
$rfd["slashdot"] = fsockopen("www.slashdot.org",80);
select(1000000,$rfd);
while ( list($site,$fd) = each($rfd) )
if ( fd_isset($fd,"read") ) do_stuff($site);
?>
Another thought: would it speed things up significantly to use
constants in place of strings in fd_isset()? eg. fd_isset($rfd,
FD_READ);
Thanks, BTW. I've been wanting a select() call for a while....
Colin
--------------------------------------------
Colin Putney 604-932-0606 x21
Bit Flinger colin@whistler.net
Whistler Networks http://www.whistler.net/