Facebook PHP API without cURL extension

Recently I had a quiet weird problem to solve. We were rebuilding the entire website for one of our clients and we wanted to implement Facebook PHP API. Unfortunately, the client's website is not hosted on our servers and the remote server went quiet out of date (I guess they haven't touched it for many years).

The original Facebook PHP API on GitHub uses only cURL extension for communication with Facebook. Actually, I've never seen this error message before:

CurlException: 77: error setting certificate verify locations

This problem is quiet tricky because the cURL extension is enabled, but it just doesn't work properly. Luckily I'm not the first one who has this problem and I found this issue on the official Facebook API github page: http://github.com/facebook/php-sdk/issues/issue/121. Somebody was reporting the same problem as me and Matt Mecham recommended him his own forked version of the Facebook API that uses standard streams for downloading when the cURL extension is not enabled.

In fact this didn't solve my problem because as I've already said the cURL extension was enabled but it just didn't work. So I modified just a single line and in the end it works!

// base_facebook.php
protected function makeRequest($url, $params, $ch=null) {
    if ( function_exists( 'curl_init' ) AND function_exists("curl_exec") AND function_exists('curl_setopt_array') )

At the beginning of makeRequest function it checks whether cURL is enabled or not but we don't want to use cURL at all so modify line 505 to:

// base_facebook.php
if (false)

and leave the rest as it is.

Now the makeRequest function will always use standard fsockopen instead of cURL.

NOTE: I strongly do NOT recommend this solution. Facebook API is changing so often so your application might stop working unexpectedly. It's always better to use the official Facebook API on GitHub.

blog comments powered by Disqus