Force IPv4 in cURL in PHP application

2019-02-16 15:52发布

问题:

Is there any way to force cURL to use IPv4? I'm looking for like a global setting, like php.ini setting or something like that.

回答1:

Please try this code, with curl_setopt
This will force the IPV4 resolving.

if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
   curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}

the defined insure that the global constants available on your PHP version.