PHP Curl get Web content (IPV6 Timeout) workaround _php Tutorial

Source: Internet
Author: User
Reason:
In the program I have a strict timeout limit for curl to get content, so it will cause the problem of unable to get the content.

WORKAROUND: Set default access to IPv4.
The Curl settings for PHP are as follows:
Copy CodeThe code is as follows:
/**
* IPV6 Curl Timeout problem
*/
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, true);
Set Curl default access to IPV4
if (defined (' curlopt_ipresolve ') && defined (' curl_ipresolve_v4 ')) {
curl_setopt ($ch, Curlopt_ipresolve, CURL_IPRESOLVE_V4);
}
Sets the maximum number of seconds when curl requests a connection, and if set to 0, the infinite
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
Sets the maximum number of seconds that curl will perform the total action, and if set to 0, the infinite
curl_setopt ($ch, Curlopt_timeout, $timeout);
$file _contents = curl_exec ($ch);
Curl_close ($ch);

Note:curl_setopt ($ch, Curlopt_ipresolve, CURL_IPRESOLVE_V4) The above settings will only take effect if the version of PHP version 5.3 and later, CURL version 7.10.8 and above.

http://www.bkjia.com/PHPjc/328038.html www.bkjia.com true http://www.bkjia.com/PHPjc/328038.html techarticle cause: In the program I have made a strict timeout limit on curl acquisition, so it will cause the problem of unable to get the content. WORKAROUND: Set default access to IPv4. PHP's ...

  • 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.