Coo. I never really got into the rationale behind the C API, all that 
kernel optimization, which is interesting. I haven't had any problems yet 
with fd_clear, but I don't use it intensely. (Once, maybe twice in a 
script.)

Anyways, anything that will make the extension better is a good thing. (I'm 
just glad it won't take much to fix existing code to work with the changes.)

J
 

Jason Greene wrote:
> 
> 
> Well, since you know the C-API, lets look at if from the C socket API
> perspective. select() is designed to take 3 arrays. The problem with
> arrays is that they take up memory and processing time. In application
> space this really isn't a problem, but in the kernel, every saved byte
> counts. To optimize this they emulated arrays using bit masks. Another
> optimization they performed is to have you pass the highest file
> descriptor + 1 into select. (that way they only process part of the bit
> mask.)
> 
> 
> What I am getting at, is that FD_* was an interface designed strictly
> for kernel performance. Direct manipulation of these low level values
> does not really belong in a high-level language.
> 
> The method that makes the most sense is to use php arrays in place of
> the fd masks. Everything would work exactly the same, except it would be
> much easier to interface, it would be less buggy, and require less code.
> 
> By the way, the bug with the socket_fd_functions, is that it may set
> your maximum file descriptor incorrectly, and this would cause you to
> miss events occurring on ready sockets. (This occurs anytime you call
> socket_fd_clear() on a socket, or if you don't add sockets in order they
> were opened ex. 3, 1, 2 will cause you to lose file descriptor 3.
> 
> 
> example
> --------
> 
> <?php
> 
> // ...
> 
> $read_flds=array($socket1, $socket2, $socket3, $socket4, $socket5);
> $write_flds=array($socket6, $socket7, $socket8);
> $except_flds=array($socket9);
> 
> 
> // Wait on sockets specified in arrays, and modify them to contain
> // sockets that are ready
> $retval = socket_select($read_flds, $write_flds, $except_flds, 1);
> 
> //Perform actions on sockets waiting to be read
> foreach($read_flds as $read_sock)
> perform_read_action($read_sock);
> 
> //Perform actions on sockets waiting to be written
> foreach($write_flds as $write_sock)
> perform_write_action($write_sock);
> 
> //Perform actions on exceptions
> foreach($except_flds as $except_sock)
> process_exception($except_sock);
> 
> 
> // ...
> 
> ?>
> 
>  
> I would like to see this extension become stable so that people can
> start relying on somewhat frozen behavior.
> 
> To answer your question It should be pretty easy to port your code to
> the newer API.
>  
> 
> I appreciate hearing concerns like this, and I hope you and others
> continue to speak up. : )
> 
> -Jason
> 


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to