PHP crawl Web page with curl problem

Source: Internet
Author: User
  encapsulates a Curl Crawl Web page function, in the local test no problem, when placed on the testing server, if through the browser access to execute, most of the time the function returned by the HTTP status code return 0 , error message ' Error:name Lookup timed out ', the case of extreme Idol returns 200 success, but if executed directly on the test server with the command line, 100% succeeds. The code is as follows:  
static public Function Curlget ($url, $data = Array (), $header = Array (), $timeout = 3, $port = +) {$is _ssl = substr ($url, 0, 5) = = ' https '?        1:0;        $ch = Curl_init ();            if (!empty ($data)) {$data = Is_array ($data)? Http_build_query ($data): $data;  $url. = (Strpos ($url, '? ')? ' & ': "?") .        $data;        } curl_setopt ($ch, Curlopt_url, $url);        curl_setopt ($ch, Curlopt_returntransfer, true);        curl_setopt ($ch, Curlopt_customrequest, ' GET '); curl_setopt ($ch, curlopt_followlocation,1);        Whether to crawl the page after the jump curl_setopt ($ch, Curlopt_connecttimeout, 5);        curl_setopt ($ch, Curlopt_timeout, $timeout);        curl_setopt ($ch, curlopt_post, 0);        curl_setopt ($ch, Curlopt_port, $port);        curl_setopt ($ch, Curlopt_httpheader, $header);        curl_setopt ($ch, Curlopt_referer, $url);                curl_setopt ($ch, Curlopt_useragent, Self::url2useragent ($url)); if ($is _ssl) {curl_setopt ($ch, CURLopt_ssl_verifypeer, false);  Skip certificate Check curl_setopt ($ch, Curlopt_ssl_verifyhost, true);        Check the existence of the SSL encryption algorithm from the certificate} $result = Array ();        $result [' result '] = curl_exec ($ch);        $result [' http_code '] = Curl_getinfo ($ch, Curlinfo_http_code);        if (0! = Curl_errno ($ch)) {$result [' error '] = "error:\n". Curl_error ($ch);        } curl_close ($ch);    return $result; }
我个人感觉和代码应该关系不大,不知是哪的问题。望各路大神不吝赐教,指点迷津,不胜感激。
  • 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.