Php curl: how to obtain webpage content (timeout in IPV6)

Source: Internet
Author: User

Cause:
If IPv6 is enabled, curl will resolve IPv6 first by default. If the corresponding domain name does not have IPv6, curl will wait until the IPv6 dns resolution fails timeout before looking for IPv4 in the previous normal process. In the program, I set a strict timeout limit on the content obtained by curl, which may cause the problem that the content cannot be obtained.

Solution: Set the default access to ipv4.
The curl setting method for php is as follows:

<? =, CURLOPT_URL, expires, ('curlopt _ ipresolve') & ('curl _ IPRESOLVE_V4 ', expires, curl_setopt (, CURLOPT_CONNECTTIMEOUT, curl_setopt (, CURLOPT_TIMEOUT, * 3 = curl_exec ();


Note: curl_setopt ($ ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4) takes effect only when php version 5.3 or later, curl version 7.10.8 or later.

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.