file_get_contents默認超時時間(秒)- L% n5 F8 Z( K3 l
php.ini中的default_socket_timeout設置,默認超時時間是default_socket_timeout = 60' {2 E6 X" a" ^! C' M* [
* Z8 K" L" \! C. n如果要修改超時時間,修改第3個參數即可* B2 J, W5 _! g" ]) |
9 {4 Y+ M6 t' h3 N$ l, r/ O- ~5 M$ w$opts = array(! L+ q F% R9 |2 Q | m q( n" \+ q
'http'=>array(
% ^. Y- Z7 o: f. Z6 n2 `! `) G 'method'=>"GET",
6 j0 \4 `% C3 P- h( K+ V4 y5 B 'timeout'=>120,$ R7 g& R$ ?; c- d
)+ _$ M% N4 k* \1 S& Q
);
& b. ]9 Z% p! H6 ?) }3 ~; o, K" d0 C" r6 i/ Q
$context = stream_context_create($opts);# p6 S2 q/ k5 H) ^0 o, B
$ M2 M1 Z' g# s6 v
$html =file_get_contents('http://www.example.com', false, $context);
! k* n3 g* D1 F/ l# T, k8 g; z! Z# s |