参考:​​http://hsm.hz.blog.163.com/blog/static/100688014201161410341583/​


$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=> 1, "usec"=> 0 ) );
// 接收

socket_set_option($socket,SOL_SOCKET,SO_SNDTIMEO,array("sec"=> 3, "usec"=> 0 ) );