下面是我经常使用的判断网站链接是否可用的函数,希望对你有用。
//判断URL在指定时间内是否有相应
function checkUrl($url, $timeout = 3){
$ret = false
$handle = curl_init()
curl_setopt($handle, CURLOPT_URL,$url)
curl_setopt($handle, CURLOPT_NOBODY, true)
curl_setopt($handle, CURLOPT_TIMEOUT,$timeout)//设置默认超时时间为3秒
$result = curl_exec($handle)
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE)
curl_close($handle)
if(strpos($httpCode,'2') == 0){
$ret = true
}
return $ret
}
呵呵 ,我看你好像前面问过一个问题 是说怎么判断程序走了5秒是吧.你可能理解错了 你在new soapclent之前 只要 设置超时时间就可以了.ini_set('default_socket_timeout', 5)//设置超时时间欢迎分享,转载请注明来源:内存溢出
评论列表(0条)