|
@socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>10, "usec"=>0));当socket_read得不到响应,这里设置时间可以跳过不会陷入死循环
3 r8 b/ j: e. d4 ^5 C' v" Z. l现在socket读写数据的流程是这样的:
, I q/ l+ w2 q" h) t
$ ?& B, ~# b: C$ I6 @$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);, o6 R. v% ^1 E+ Q, L
: U9 e3 C: k( R1 Q9 U; D" D
socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>60, "usec"=>0 ) );
( V3 r) R8 g% G1 |2 N
& E8 w% a( j3 I5 s2 V! O/ @socket_connect($socket, IP, PORT);/ e) u6 Q- q$ d
5 R/ G" K. j; V& M+ k
socket_write($socket, $strxml, strlen($strxml);
+ z2 K( z9 T* ~0 ? G/ F# V$back = socket_read($socket, 8192);. u; R( e }# d& @+ v9 | R
! x) f& x2 ?& b, lsocket_read有时候收不到返回数据,应该是超时了,如何修改超时时间?6 H; I' Y m0 C7 W- @
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>3, "usec"=>0));//接受超时( |, x- ]0 }5 k5 b3 [/ w% v
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>2, "usec"=>0));//发送超时4 \; o' M. u# { l) @
% B& [7 d1 z. e+ L6 j* ]8 U
https://blog.csdn.net/sn_qmzm521/article/details/80756396
$ q* q3 n/ B2 ghttps://blog.csdn.net/Hiking_Tsang/article/details/84788448
^& _& _3 f8 u# f
3 A; S3 A# V# N: w |
|