file_get_contents默認超時時間(秒)
7 U2 r9 j& m5 q+ P5 sphp.ini中的default_socket_timeout設置,默認超時時間是default_socket_timeout = 601 [. \, y' p7 E
! E' U; [$ E o4 t, Z+ y' i3 h
如果要修改超時時間,修改第3個參數即可
4 U( b- d# {$ u7 Q+ K) ]* `
1 S' T$ k! F+ y4 }5 R9 Z# ^ c k( f$opts = array(
1 b6 |+ r% f7 T+ J9 U 'http'=>array() p. Y% k' l+ r% Y1 R4 ~
'method'=>"GET",
9 b4 |* \0 F! [ y" t3 V' |) O 'timeout'=>120,
5 E7 a! K( B9 U# Q- x; B; y1 J )
4 V, R+ ~! b" |& Z);
1 Q: w# B; |) x0 d _3 l9 G( F( R9 M- C
$context = stream_context_create($opts);# R% g2 u& w1 `2 G5 F! @* ]
* G: d3 Z6 j |" t% o
$html =file_get_contents('http://www.example.com', false, $context);
& }' J# P, C( t( U; ?" z+ R! n |