rackspace-cloudfiles

Rackspace Cloud Files - [curl] 6: Couldn't resolve host 'identity.api.rackspacecloud.com' Exception thrown


The code below in localhost works fine and in server it throws an error [curl] 6: Couldn't resolve host 'identity.api.rackspacecloud.com'

$client = new Rackspace(Rackspace::UK_IDENTITY_ENDPOINT, array(
                    'username' => $username,
                    'apiKey' => $apiKey,
                    'ssl.certificate_authority' => false,
                    'curl.options' => array('debug' => true, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4)
            ));

I ping in server identity.api.rackspacecloud.com and it works fine. And I followed this documentation to try to authenticate using curl: http://docs.rackspace.com/servers/api/v2/cs-devguide/content/curl_authentication.html

This is the request I sent across:

curl -s https://lon.identity.api.rackspacecloud.com/v2.0/tokens -X 'POST' -d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"xxxx", "apiKey":"yyyyyyyy"}}}' -H "Content-Type: application/json" | python -m json.tool 

It return the result.

But when I run the php code, it throws an error.. Kindly guide me to find the issue.

Edit:

        $data_string = '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"xxxxxxx", "apiKey":"yyyyyyyyyy"}}}';//json_encode($data);
        $ch = curl_init('https://lon.identity.api.rackspacecloud.com/v2.0/tokens');
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
        );
        echo $result = curl_exec($ch);
        if(curl_errno($ch)){
            echo 'Curl error: ' . curl_error($ch);
        }

I test the above code in local as well as server and in local, it works fine but not in live. change the CURLOPT_SSL_VERIFYPEER TRUE and FALSE. Nothing works.

Note:

OS: CentOS


Solution

  • Adding Google DNS nameserver, solves the problem.

    In server, the nameserver defined in /etc/resolv.conf is

    nameserver 83.138.151.80
    nameserver 83.138.151.81
    

    which is recommended nameserver by Rackspace for UK.

    So the curl in command prompt works, but not work in php. So I decide to add google DNS along with it. Now the /etc/resolv.conf like this:

    nameserver 83.138.151.80
    nameserver 83.138.151.81
    nameserver 8.8.8.8
    

    Everything works fine...