Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
803 views
in Technique[技术] by (71.8m points)

facebook - PHP Curl CURLOPT_IPRESOLVE

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...