Facebook SDK v4 behind a proxy

This is a really short note.

If You try to use this SDK behind a proxy e.g. in a Drupal site with simple_fb_connect module You may experience that the SDK wont honor Your proxy_server settings done sitewide. All requests try to go to FB servers directly and timing out. 🙁

I made the change below to workaround this.

--- facebook-php-sdk-v4/src/Facebook/HttpClients/FacebookCurlHttpClient.php.orig        2016-04-04 21:42:21.846561162 +0200
+++ facebook-php-sdk-v4/src/Facebook/HttpClients/FacebookCurlHttpClient.php     2016-04-04 21:55:18.024673677 +0200
@@ -178,6 +178,8 @@
       CURLOPT_SSL_VERIFYHOST => 2,
       CURLOPT_SSL_VERIFYPEER => true,
       CURLOPT_CAINFO         => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem',
+      CURLOPT_PROXY    => variable_get('proxy_server',''),
+      CURLOPT_PROXYPORT        => variable_get('proxy_port',''),
     );

     if ($method !== 'GET') {

Now the requests going to the proxy.

I didnt found any other solutions on the Internet. This may mean that there is a trivial point somewhere for this setting which I didnt found or nobody used before that SDK behind proxy?

Leave a Reply