Home > Backend Development > PHP Tutorial > Solution to php curl obtaining web page content (timeout under IPV6)_PHP tutorial

Solution to php curl obtaining web page content (timeout under IPV6)_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:00:48
Original
960 people have browsed it

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.

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template