不好意思
我使用file_get_contents
函数获取"www.example.com"的HTML内容作为字符串,然后处理该字符串。
我的问题是,当这个网站需要很多时间打开,我想设置超时为我的脚本的一部分(不是所有的脚本),这样,如果file_get_contents
功能需要很多时间,我的脚本将停止它,并继续下一行。我使用php5这是可能的吗?我感谢你所有的建议
的例子:
//set time out = 10S
$siteStr = @file_get_contents("www.example.com");
//10S is finished so stop file_get_contents and continue
use curl
function get_data($url) {
$ch = curl_init();
$timeout = 10;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}