function Url_exists ($url)
{
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_NOBODY, 1); // 不下载 curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); return (curl_exec($ch)!==false) ? true : false;
}
Use this function to determine whether the URL exists, the incoming URL if the letter can quickly determine whether the existence of the incoming URL is Chinese, the judgment will become very slow, why? What is the improvement method?
Reply content:
function Url_exists ($url)
{
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_NOBODY, 1); // 不下载 curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); return (curl_exec($ch)!==false) ? true : false;
}
Use this function to determine whether the URL exists, the incoming URL if the letter can quickly determine whether the existence of the incoming URL is Chinese, the judgment will become very slow, why? What is the improvement method?
For reference http://blog.csdn.net/ashelyhss/article/details/7916970
Hope to help ~:)
Set rules to filter non-URLs first, if you use curl
Then determine if the URL exists based on the headers information returned
Next there is a handy function get_headers () non-URL will return false the normal URL will return headers information and then determine the HTTP status is OK