file_get_contents默認超時時間(秒)
3 j# |- F- E3 V' D6 d @php.ini中的default_socket_timeout設置,默認超時時間是default_socket_timeout = 60
4 X5 y0 b7 B/ }
6 g; e' }+ o( j如果要修改超時時間,修改第3個參數即可0 d7 R2 r" v9 S1 `
- i' |5 V' g9 B' D3 Y( Y5 o( Y$opts = array(
6 w$ X0 x' f2 z+ k6 o# S2 q 'http'=>array(
$ H: h3 D! ~$ h1 r0 T: i; e 'method'=>"GET",% [5 h. o" f) k4 F8 g
'timeout'=>120,
6 Y& H) x: ^* K* ?* @ )
' o) h( h7 C) s1 W, t. s);6 D! o9 ]! F7 v/ D8 A+ F% F. I5 u
7 i) D5 v2 d7 h8 \3 b$context = stream_context_create($opts);
! \6 _8 Q, P, n" u0 i4 l& `% P" h& x) e# C o
$html =file_get_contents('http://www.example.com', false, $context);
/ @: `" ]8 i! v2 V% j; Y$ `# V0 i |