|
@socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>10, "usec"=>0));当socket_read得不到响应,这里设置时间可以跳过不会陷入死循环
9 a1 }2 N) [6 _4 P) x现在socket读写数据的流程是这样的:' M2 x ^# D8 W+ P# ~4 b$ K; ~
: k; l* [9 A7 E8 S5 G
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);4 v! u" u9 G l! R+ }3 _
4 T, q( y/ P$ B( n& d5 Q& R( o( Vsocket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>60, "usec"=>0 ) );: L/ Z0 C/ Q/ r: p
: A2 q; n! ^( z% t9 tsocket_connect($socket, IP, PORT);' W: X1 g8 f4 H7 Y
7 o- r; _& ~8 Y; D asocket_write($socket, $strxml, strlen($strxml);
: y& |+ b7 o2 ]$back = socket_read($socket, 8192);- \4 G7 h: l* U
- P' P8 y& S: W- Q& D, L. N
socket_read有时候收不到返回数据,应该是超时了,如何修改超时时间?
2 T5 n. g4 a% s6 V$ H) tsocket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>3, "usec"=>0));//接受超时: ]5 R, N1 P* j9 g6 G
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>2, "usec"=>0));//发送超时
$ L8 ~3 V4 A/ H6 Y4 B5 \1 r4 k& p' o, b$ m
https://blog.csdn.net/sn_qmzm521/article/details/80756396" J5 e( @/ C& A1 u! q! f6 j
https://blog.csdn.net/Hiking_Tsang/article/details/84788448
c/ {: g, b/ J# R7 y
7 g- X- U9 X) J) i |
|