Cause:
In the program, I have set a strict timeout limit for curl to obtain the content, so it will cause the problem of being unable to obtain the content.
Solution: Set the default access to ipv4.
The curl setting method of PHP is as follows:
Copy the code The code is as follows:
/**
* curl timeout issue under IPV6
*/
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
//Set curl's default access to IPv4
if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
// Set the maximum number of seconds for curl to request a connection. If set to 0, it will be infinite.
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//Set the maximum number of seconds for curl to perform total actions. If set is 0, then infinite
curl_setopt ($ch, CURLOPT_TIMEOUT,$timeout*3);
$file_contents = curl_exec($ch);
curl_close($ch);
Note: curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4) The above settings only take effect when php version 5.3 and above, curl version 7.10.8 and above.
http://www.bkjia.com/PHPjc/328038.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328038.htmlTechArticleReason: In the program, I have set strict timeout limits for curl to obtain content, so it will cause failure Problems getting content. Solution: Set the default access to ipv4. php...