Socket_select (), please explain the great God

Source: Internet
Author: User
Ask God to help explain the function of Socket_select (), see PHP Manual is generally meant to be blocked, what is the case of blocking, when continue to execute AH, the parameters are as follows
int Socket_select (array & $read, array & $write, array & $except, int $tv _sec [, int $tv _usec = 0]);//sock Et_select () accepts arrays of sockets and waits for them to the change status.  Those coming with BSD sockets background//will recognize that those socket resource arrays is in fact the so-called file Descriptor sets. Three independent arrays of//socket Resources is watched.//param/*readthe sockets listed in the read array would be watch Ed to see if characters become available for reading (more precisely, to see if a read would not block-in particular, a s Ocket resource is also ready on end-of-file, in which case a socket_read () would return a zero length string). Writethe Sock ETS listed in the write array would be watched to see if a write would not block.exceptthe sockets listed in the except Arra Y'll be watched for exceptions.tv_secthe tv_sec and tv_usec together form the timeout parameter. The timeout is a upper bound on the amount of time elapsed before Socket_seLect () return. Tv_sec May is zero, causing socket_select () to return immediately. This was useful for polling. If Tv_sec is NULL (no timeout), Socket_select () can block indefinitely.*/


Reply to discussion (solution)

Where do you see the blockage?
Socket_select accepts three socket sets of words to check if the socket in the array is in an operational state (only operational sockets are left on return)
The most used is $read, so take read as an example
Initially, you should have a server-side listener socket in the socket string $read
Whenever the socket is readable, it indicates that a user initiated the connection. At this point you need to create a socket for the connection and add it to the $read array
Of course, not only the server-side listener socket will become readable, the user socket will also become readable, you can read the data sent by the user
Socket_select only returns if the socket group has changed. That is, once you execute the next statement to Socket_select, you must have a socket that you want to manipulate.

Thank you, God, for the general understanding.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.