|
@socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>10, "usec"=>0));当socket_read得不到响应,这里设置时间可以跳过不会陷入死循环
5 ]# o5 M9 s+ w1 ]. Q$ O, q* Z现在socket读写数据的流程是这样的:) [( B0 Y4 }5 r' x3 H, p6 c
! M X5 h# k; ^4 K( t( h$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);6 N1 c$ F5 Z+ q {7 H/ O
3 y: p9 Q' e( L3 J" H+ t. Lsocket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>60, "usec"=>0 ) );/ s! u* [* T% }) {; U9 Q
' d: z* Z/ F5 T, W
socket_connect($socket, IP, PORT);
o6 s" o. F2 C8 a
$ j5 l8 H) Z3 b" Wsocket_write($socket, $strxml, strlen($strxml);7 v# I3 H) }, g3 F, l8 i
$back = socket_read($socket, 8192); {% X( `, c( u: b& T
8 ^9 U2 }, R/ i7 ]3 n' |socket_read有时候收不到返回数据,应该是超时了,如何修改超时时间?( z& r) D" g# ^* f! |$ X9 U, r% B
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>3, "usec"=>0));//接受超时
" {2 X4 u- t% bsocket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>2, "usec"=>0));//发送超时
# z9 G6 W- K, f4 f* w2 H$ B+ d' \- t* N$ s7 m- y
https://blog.csdn.net/sn_qmzm521/article/details/807563968 V: C% Y! a& G' F g# ^1 ]
https://blog.csdn.net/Hiking_Tsang/article/details/84788448
8 k( m/ e4 C: Y" h' V4 G% M* G7 k# q+ Z5 [; k5 K u
|
|