本文章地址:https://wutong.me/2017/10/11/php-set-socket-timeout.html 转载请注明出处

介绍如何设置超时时间的方法。

//读超时
socket_set_option($client, SOL_SOCKET, SO_RCVTIMEO, [
    'sec'=>8,
    'usec'=>0,
]);
//写超时
socket_set_option($client, SOL_SOCKET, SO_SNDTIMEO, [
    'sec'=>8,
    'usec'=>0,
]);