PHP socket link. can I set the time? PHPcode $ socketsocket_create (AF_INET, SOCK_STREAM, SOL_TCP); $ IP $ row [IP]; $ connectionsocket_connect ($ socket, $ IP, 2012); the default value is 30 seconds, if it cannot be connected, it will take too long for the PHP socket link to be connected. can you 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 value is 30 seconds. if it cannot be connected, it will take too long. can I set it to only 10 seconds?
------ Solution --------------------
There are actually a lot of useful references in the user comment area of the online manual, 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 are too 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 control prevents data from being sent. array. the array will contain in two keys: sec which is the seconds part on the timeout value and usec which is 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 level SO_SNDTIMEO, // timeout option array ("sec" => 10, // Timeout in seconds "usec" => 0 // I assume timeout in microseconds ));
------ Solution --------------------
Discussion
Reference:
There are actually a lot of useful references in the user comment area of the online manual, 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 are too lazy, extract a piece of code for you.
SO_SNDTIMEO Reports the timeout value specifying ......
------ Solution --------------------
In this way, the connected php code is put into a separate file, accessed using AJAX, and the result is put into a p