PHP Curl CURLOPT_IPRESOLVE

一世执手 提交于 2020-01-19 13:35:36

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/11220416/php-curl-curlopt-ipresolve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!