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:
|The code is as follows:||Copy code|
$ Ch = curl_init ();
// Sets the maximum number of seconds for a curl request to connect. If it is set to 0, it is unlimited.
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.