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.
Thanks that did the trick:
apt-get install ca-certificates
Thanks! This helped a lot. Was starting to tear out my hair not knowing why one server was working while the other failed.
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
Installing ca-certificates solved my issue. Thanks a lot for documenting this, saved me a lot of time.
Turns out although the CA import worked, cURL doesn’t recognize the new certificates 🙁
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.
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!
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
This is great – thanks for the detailed writeup – saved me some time for sure.
-Phil