1

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

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
  • Have you tried with basic curl.options? curl also have verify_peer prpery. Not sure if its SSL fault tho. Maybe try basic curl call to identify if it's curl's fault or ``Rackspace``'s – Grzegorz Nov 18 '14 at 07:10
  • @Gacek I try basic curl call...still it throws an error. – Tamil Selvan C Nov 20 '14 at 11:25
  • I would try, in your place, to get different maybe more "standard" configuration server and try if it works. Does basic curl work at all? try fetching http://google.com? Maybe its problem with server libraries not with your app? – Grzegorz Nov 20 '14 at 11:35

1 Answers1

1

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...

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70