Force IPv4 in cURL in PHP application

2019-02-16 14:53发布

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条回答
Melony?
2楼-- · 2019-02-16 15:58

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.

查看更多
登录 后发表回答