PHP Curl CURLOPT_IPRESOLVE [英] PHP Curl CURLOPT_IPRESOLVE
问题描述
我一直在Facebook的应用程序使用facebook图形API的身份验证,最近Facebook升级到IPv6和我的网络不支持IPv6所有我的呼叫开始返回主机是不可达的错误,我在Facebook上搜索bug和发现我们仍然可以使用强制的请求到Facebook使用CURL CURLOPT_IPRESOLVE使用IPv4。
现在当我尝试使用curl发送请求到Facebook Graph API我得到
注意:使用未定义的常量CURLOPT_IPRESOLVE - 假定为CURLOPT_IPRESOLVE
我想知道如何启用对此常量的支持,所以我可以使用IPv4向Facebook Graph API发送请求。
我的代码是
code> $ url =(https://graph.facebook.com/me/access_token?tokrn);
$ c = curl_init();
curl_setopt($ c,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ c,CURLOPT_URL,$ url);
curl_setopt($ c,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
$ content = curl_exec($ c);
$ err = curl_getinfo($ c,CURLINFO_HTTP_CODE);
curl_close($ c);感谢解决方案
CURLOPT_IPRESOLVE可从curl 7.10.8开始使用
>
尝试此示例代码测试
<?php
$ version = curl_version();
//这些是可以使用的位域
//检查curl构建中的功能
$ bitfields = Array(
'CURL_VERSION_IPV6',
'CURLOPT_IPRESOLVE'
);
foreach($ bitfields as $ feature)
{
echo $ feature。 ($ version ['features']& constant($ feature)?'matches':'不匹配');
echo PHP_EOL;
}
FYI: http://gcov.php.net/PHP_5_3/lcov_html/curl/interface.c.gcov.php p>
I have been working on a facebook application which uses facebook graph API for authentication, recently facebook upgraded to IPv6 and my network does'nt support IPv6 so all of my calls started returning Host is unreachable error, I searched on facebook bugs and found that we can still use force the requests to facebook to use IPv4 using CURL CURLOPT_IPRESOLVE.
Now when I try to send request to Facebook Graph API using curl I get Notice: Use of undefined constant CURLOPT_IPRESOLVE - assumed 'CURLOPT_IPRESOLVE'
I want to know how can I enable support for this constant or how can I disable IPv6 support in php so that I can send request to Facebook Graph API using IPv4.
My code is
$url = ("https://graph.facebook.com/me/access_token?tokrn"); $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); $contents = curl_exec($c); $err = curl_getinfo($c,CURLINFO_HTTP_CODE); curl_close($c);
Thanks
解决方案Check you curl version
CURLOPT_IPRESOLVE is available since curl 7.10.8
Try this sample code to test
<?php $version = curl_version(); // These are the bitfields that can be used // to check for features in the curl build $bitfields = Array( 'CURL_VERSION_IPV6', 'CURLOPT_IPRESOLVE' ); foreach($bitfields as $feature) { echo $feature . ($version['features'] & constant($feature) ? ' matches' : ' does not match'); echo PHP_EOL; }
FYI: http://gcov.php.net/PHP_5_3/lcov_html/curl/interface.c.gcov.php
这篇关于PHP Curl CURLOPT_IPRESOLVE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文