php检测url是否存在
function file_exists($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
//不下载
curl_setopt($ch, CURLOPT_NOBODY, 1);
//设置超时
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == 200 || $http_code == 301) {
return true;
}
return false;
}