Curl determines if the URL exists

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.