Cause: If IPv6 is enabled, curl will resolve IPv6 first by default. if the corresponding domain name does not have IPv6, wait until IPv6dns resolution fails timeout before looking for IPv4 in the previous normal process, in the program...
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.
The solution is to set the default access to ipv4. the curl setting method of php is as follows:
$ Ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true ); // set the default curl 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 for curl request connection. if it is set to 0, the value of curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout) is unlimited ); // sets the maximum number of seconds for curl to execute the action. if it is set to 0, the value of curl_setopt ($ ch, CURLOPT_TIMEOUT, $ timeout * 3) is infinite; $ file_contents = curl_exec ($ ch ); curl_close ($ ch );
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.
Link to this article:
Add to favorites ^ please keep the tutorial address.