Socket_select (). could you please help me explain the functions of socket_select ()? refer to the php Manual for blocking. what is the blocking situation, when can I continue execution? the parameters are as follows:
int socket_select ( array &$read , array &$write , array &$except , int $tv_sec [, int $tv_usec = 0 ] );//socket_select() accepts arrays of sockets and waits for them to change status. Those coming with BSD sockets background //will recognize that those socket resource arrays are in fact the so-called file descriptor sets. Three independent arrays of //socket resources are watched.//param/*readThe sockets listed in the read array will be watched to see if characters become available for reading (more precisely, to see if a read will not block - in particular, a socket resource is also ready on end-of-file, in which case a socket_read() will return a zero length string).writeThe sockets listed in the write array will be watched to see if a write will not block.exceptThe sockets listed in the except array will be watched for exceptions.tv_secThe tv_sec and tv_usec together form the timeout parameter. The timeout is an upper bound on the amount of time elapsed before socket_select() return. tv_sec may be zero , causing socket_select() to return immediately. This is useful for polling. If tv_sec is NULL (no timeout), socket_select() can block indefinitely.*/
Reply to discussion (solution)
Where do you see it as blocking?
Socket_select accepts three socket arrays, and checks whether the sockets in the array are in the operational status (only the operable sockets are retained when returned)
The most commonly used is $ read. Therefore, read is used as an example.
In the socket array $ read, a server listening socket is initially required.
Each time the socket is readable, a user initiates a connection. In this case, you need to create a socket for the connection and add it to the $ read array.
Of course, not only the socket listened by the server will become readable, but also the user socket will become readable. now you can read the data sent by the user.
Socket_select is returned only when the socket array changes. That is to say, once the next statement of socket_select is executed, a socket is required for your operation.
Thank you!