socket_connect does not timeout

后端 未结 4 1923
说谎
说谎 2021-01-03 09:48

I am using sockets to send data to a server that may not be responding. So I am trying to define a timeout by using this solution in SO.

Make PHP socket_connect time

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 10:40

    I changed my socket communication mechanism to use stream_socket_client ($remote_socket, &$errno, &$errstr, $timeout) function instead. This function allows to define the connect timeout unlike socket_connect ($socket, $address, $port) which doesn't.

    To force a timeout using socket_connect see @bigtallbill answer.

提交回复
热议问题