方法一:
/**
* 检测网址连接是否可用
**/
function check_url($url){
if (@fopen($url, 'r')==false) {
return false;
}
return true;
}
方法二:
/**
* 检测网址连接是否可用
**/
function check_url($url){
$httpcode = 0;
$ch = curl_init();
$timeout = 1; // 设置超时的时间[单位:秒]
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch,CURLOPT_URL,$url);
curl_exec($ch);
# 获取状态码赋值
$httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 200){
return true;
}else{
return false;
}
}