PHP socket link, can I set the time? How to fix it

Source: Internet
Author: User
PHP socket link, can I set the time?
PHP Code
  
   $socket = Socket_create (Af_inet, Sock_stream, sol_tcp);  $IP = $row [' IP ']; $connection = Socket_connect ($socket, $IP, 2012);  

It seems that the default is 30 seconds, if not even the time is too long, can you set it only 10 seconds?

------Solution--------------------
The user annotation area of the online manual has a lot of useful references, you can search for timeout in the http://php.net/manual/en/function.socket-get-option.php, because this problem is very common, so there is certainly.
If you're lazy, extract a piece of code for you

So_sndtimeo Reports The timeout value specifying the amount of time that an output function blocks because flow contro l prevents data from being sent.array. The array would contain keys:sec which is the seconds part on the timeout value and USEC which are the microsecond part of the timeout value.
To set a socket timeout value (assuming you ' ve set it blocking) use:

PHP code
socket_set_option ($socket, sol_socket,//Socket Lev El So_sndtimeo,//timeout Option Array ("SEC" =>10,//timeout in seconds "usec" =>0//I-assume timeout in microseconds)); 
------Solution--------------------
discussion

Reference:

User Comment area of the online manual there's actually A lot of useful references, you can search for timeout in the http://php.net/manual/en/function.socket-get-option.php, because this problem is very common, so there will certainly be.
If you're lazy, extract a piece of code to you

So_sndtimeo Reports The timeout value specifying ...

------Solution--------------------
to put the connected PHP code in a separate file, with Ajax access, and put the result in a DIV
  • Related Article

    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.