21,886
社区成员
发帖
与我相关
我的任务
分享
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, 'http://localhost/index.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$con = curl_exec($ch);
curl_close($ch);
注:url是外网的完全没问题,只要是系统服务器和url所在服务器是同一个,就出不来,崩溃中
<?php
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 1 //设置一个超时时间,单位为秒
)
)
);
file_get_contents("http://example.com/", 0, $ctx);
?>