Skip to content

Instantly share code, notes, and snippets.

@eddy8
Last active August 29, 2015 14:00
Show Gist options
  • Save eddy8/11163923 to your computer and use it in GitHub Desktop.
Save eddy8/11163923 to your computer and use it in GitHub Desktop.
check url exist
<?php
/**
* 判断URL是否存在/可访问
* @param string $url url
* @return bool 存在返回true。不存在返回false
*/
function url_exist($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 3);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($curl, CURLOPT_NOBODY, 1);
curl_exec($curl);
$http_code = curl_getinfo($curl,CURLINFO_HTTP_CODE);
if ($http_code === 200) {
return true;
} else {
return false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment