<?php
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 1 //设置一个超时时间,单位为秒
)
)
);
file_get_contents("http://example.com/", 0, $ctx);
?>
Can set a timeout, the function itself can be encapsulated
Reproduced in: https: //www.cnblogs.com/in-loading/archive/2012/07/25/2607783.html