title: Facebook API - timed out before SSL handshake
body: <p>I'm facing this issue with the Facebook PHP SDK. My application is hosted on AWS EC2 (Virginia).</p>
  
  <p>It's randomly happening but has recently increased. I've read that it was necessary to specified some cURL options, so I've done so:</p>
  
  <pre><code>self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
  self::$CURL_OPTS[CURLOPT_SSLVERSION] = 3;
  self::$CURL_OPTS[CURLOPT_CONNECTTIMEOUT] = 20;
  </code></pre>
  
  <ul>
  <li>Because IPv6 is not supported on EC2 instance, we need to force IPv4</li>
  <li>I've read to force SSL version 3</li>
  <li>I've tried to increase the timeout from 10 to 20 seconds</li>
  </ul>
  
  <p>I'm still getting the following error:</p>
  
  <blockquote>
    <p>FacebookAPIException: timed out before SSL handshake</p>
  </blockquote>
  
  <p>Which I believe is not a Facebook exception but a cURL exception.
  I can't really enable the verbose mode because I have many requests and just a small percentage is failing at the moment.</p>
  
  <p>Anyone is having the same issue?</p>
  
  <p>My system:</p>
  
  <pre><code>Centos Linux 2.6.32-431.5.1.el6.x86_64 #1 SMP Wed Feb 12 00:41:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
  
  libcurl.x86_64 7.19.7-37.el6_4
  
  php curl
  cURL support =&gt; enabled
  cURL Information =&gt; 7.19.7
  ...
  Protocols =&gt; tftp, ftp, telnet, dict, ldap, ldaps, http, file, https, ftps, scp, sftp
  Host =&gt; x86_64-redhat-linux-gnu
  SSL Version =&gt; NSS/3.14.0.0
  ZLib Version =&gt; 1.2.3
  libSSH Version =&gt; libssh2/1.4.2
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE</strong> </p>
  
  <p>I've opened a Facebook bug here: <a href="https://developers.facebook.com/x/bugs/1461144600769806/" rel="nofollow">https://developers.facebook.com/x/bugs/1461144600769806/</a></p>
  
  <hr>
  
  <p><strong>UPDATE 2</strong> </p>
  
  <p>My facebook bug has been closed without any useful answer.
  I've managed to log the verbose debug of cURL for this error:</p>
  
  <pre><code>Verbose log: 
  * About to connect() to graph.facebook.com port 443 (#0)
  *   Trying 173.252.100.27... * connected
  * Connected to graph.facebook.com (173.252.100.27) port 443 (#0)
  * Initializing NSS with certpath: sql:/etc/pki/nssdb
  *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
    CApath: none
  * timed out before SSL handshake
  * NSS error -5978
  * Closing connection #0
  </code></pre>
  
  <p>On success cURL is doing the following:</p>
  
  <pre><code>Verbose log: 
  * About to connect() to graph.facebook.com port 443 (#0)
  *   Trying 173.252.112.23... * connected
  * Connected to graph.facebook.com (173.252.112.23) port 443 (#0)
  * Initializing NSS with certpath: sql:/etc/pki/nssdb
  *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
    CApath: none
  * SSL connection using SSL_RSA_WITH_RC4_128_SHA
  * Server certificate:
  *   subject: CN=*.facebook.com,O="Facebook, Inc.",L=Palo Alto,ST=California,C=US
  *   start date: Oct 28 00:00:00 2013 GMT
  *   expire date: Aug 05 23:59:59 2015 GMT
  *   common name: *.facebook.com
  *   issuer: CN=VeriSign Class 3 Secure Server CA - G3,OU=Terms of use at https://www.verisign.com/rpa (c)10,OU=VeriSign Trust Network,O="VeriSign, Inc.",C=US
  &gt; POST /xxxxxxxxxxx/feed HTTP/1.1
  User-Agent: facebook-php-3.2
  Host: graph.facebook.com
  Accept: */*
  Content-Length: 244
  Content-Type: application/x-www-form-urlencoded
  </code></pre>
  
  <p>Errors happen randomly. So is it coming from Facebook of from my server?</p>