Last active
August 29, 2015 14:00
-
-
Save eddy8/11163923 to your computer and use it in GitHub Desktop.
check url exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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