Re: [PHP4BETA] select() Design Notes
| From: | Evan Klinger | Date: | Mon, 06 Dec 1999 18:56:25 +0000 |
| Subject: | Re: [PHP4BETA] select() Design Notes | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-7544@lists.php.net to get a copy of this message | ||
"Thies C. Arntzen" wrote:
>
> On Mon, 6 Dec 1999, Joey wrote:
>
> > Or, an idea, return an assoc. array, indexed by fd, with things like
> > read/write, got an exception, etc. per fd?
>
> array indices are strings or integers. an fd is a resource - so that won't
> work.
>
> but we could have:
>
> array("read" => array(/* of fds */),"write" => ...
>
> tc
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.
Example Use:
<?
$rfd = fsockopen("www.php.net",80);
$rfd2 = fsockopen("www.slashdot.org",80);
$fd = array($rfd,$rfd2);
select(10000000,$fd);
if(fd_isset($rfd,"read")) { do_stuff(); }
elseif(fd_isset($rfd2,"read")) { do_other_stuff(); }
else { echo 'Connection was closed'; }
?>
In its current form, if the connection was closed then fd_isset() will
return true. Is there a way to see if the connection was closed?
Comments?
--
ev
----------------------------
Evan Klinger evan@php.net
AIM evan715