Troubleshooting: PHP API for Cloud Files Stops at Authentication

and revised January 24, 2010

The PHP API for Cloud Files does not catch CURL errors. An exception will be thrown, however it will not contain any useful information to troubleshoot the problem. Here is a likely symptom and a solution.

Symptoms

You may notice messages in the stack trace about being unable to authenticate, but no reason as to why. For example, using the WordPress CDN Tools plugin, the error message might look like the following:

Fatal error: Uncaught exception 'InvalidResponseException' with message 'Unexpected response (): ' in

Solution

The problem that I ran into was missing CA certificates. It was resolved by running the following command on my Ubuntu box:

sudo aptitude install ca-certificates

An alternative is to ignore certificates altogether, which from a security standpoint is not very wise. But if you are desperate, add the following to cloudfiles_http.php line 210 (as of the time of this writing, the current version is 1.3.0). There should be a block of curl_setopt() commands. Add the command before the curl_exec().

curl_setopt($curl_ch, CURLOPT_SSL_VERIFYPEER, false);

If that fails and the exception messages are not telling you what the problem is, it could be something different altogether. In this worst case scenario, place the following line just after the curl_exec() but before curl_close().

print curl_error($curl_ch);

That should then give you the necessary information to correct the problem.

Good luck and feel free to post a comment if you discover different problems or solutions to the PHP API for Cloud Files.

9 comments… add one

  • Rob Evans Feb 7, 2013

    Thanks that did the trick:

    apt-get install ca-certificates

  • Justin Carmony Apr 11, 2011

    Thanks! This helped a lot. Was starting to tear out my hair not knowing why one server was working while the other failed.

  • randulo Apr 24, 2010

    After checking all the SSL and cURL stuff, it was all right. Downloading the cert and renaming it did the trick for us:

    cd /usr/local/share
    mkdir curl
    cd curl
    wget “http://curl.haxx.se/docs/caextract.html”
    ln cacert.pem curl-ca-bundle.crt

  • Sky Jan 2, 2010

    Installing ca-certificates solved my issue. Thanks a lot for documenting this, saved me a lot of time.

  • Mike Oct 17, 2009

    Turns out although the CA import worked, cURL doesn’t recognize the new certificates :-(

  • Mike Oct 17, 2009

    You can import the CA bundle if you’re running Mac OS X by opening Keychain Access, then clicking on the ‘System’ keychain, then click File > Import Items… and choose the cacert.pem file.

  • Andrew Sep 15, 2009

    Excellent. I’m glad I found this as when I first installed the API it threw the same error. It looks like it was updated to allow alternate CAs – this is in the documentation:
    ($auth->ssl_use_cabundle(); # bypass cURL’s old CA bundle)

    But when I put that in, it still didn’t work. Doing an aptitude install did the trick. Thanks!

    • omprakash Jun 21, 2011

      Hi Andrew

      I am also getting this error and i tried the second option changes cloudfiles_http.php but it still not working. I need help: how to install the ca certificate on my linux server. And also tell me how to remove or uninstall if it causes problem

  • Phil Apr 9, 2009

    This is great – thanks for the detailed writeup – saved me some time for sure.

    -Phil

Leave a Comment


nine − 9 =