|
@socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>10, "usec"=>0));当socket_read得不到响应,这里设置时间可以跳过不会陷入死循环) i# G j, O7 x2 C
现在socket读写数据的流程是这样的:
% M9 f5 Z4 g9 J3 [3 P& }% j: K O: W$ @5 m# R
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);/ c" N: d) b* d, n- a/ ?% X! g% R
" ]) x2 \* \2 ?# r5 W
socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>60, "usec"=>0 ) );- A( J2 u2 I5 F. i' O0 a# F3 C
! L: _( E" Y2 Q& _! @socket_connect($socket, IP, PORT);/ Y0 u) x# E# p |
8 N8 j+ z5 ]$ I" w- jsocket_write($socket, $strxml, strlen($strxml);
- ~" ~( |- X! N, v3 h+ N$back = socket_read($socket, 8192);6 ?# J. j8 e! s; m2 f/ A
4 h0 J7 q' ~, |9 R! O% n
socket_read有时候收不到返回数据,应该是超时了,如何修改超时时间?
7 G3 {( B9 _* [socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>3, "usec"=>0));//接受超时
% k, i+ k* U) {- \: h7 i, Y+ dsocket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>2, "usec"=>0));//发送超时
3 r& v2 D# \9 c; J G+ i. V L4 I$ |! a% [- N* F) O0 w, N
https://blog.csdn.net/sn_qmzm521/article/details/80756396
% p0 V. I! b/ \) @https://blog.csdn.net/Hiking_Tsang/article/details/84788448
, o( Z& W. x: t6 i: s1 J* r4 d3 q) B( C* h
|
|