title: cURL/PHP Request Executes 50% of the Time
body: <p>After searching all over, I can't understand why cURL requests issued to a remote SSL-enabled host are successful only 50% or so of the time in my case. Here's the situation: I have a sequence of cURL requests, all of them issued to a HTTPS remote host, within a single PHP script that I run using the PHP CLI. Occasionally when I run the script the requests execute successfully, but for some reason most of the times I run it I get the following error from cURL:</p>
  
  <pre><code>* About to connect() to www.virginia.edu port 443 (#0)
  *   Trying 128.143.22.36... * connected
  * Connected to www.virginia.edu (128.143.22.36) port 443 (#0)
  * successfully set certificate verify locations:
  *   CAfile: none
    CApath: /etc/ssl/certs
  * error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 alert bad record mac
  * Closing connection #0
  </code></pre>
  
  <p>If I try again a few times I get the same result, but then after a few tries the requests will go through successfully.  Running the script after that again results in an error, and the pattern continues. Researching the error 'alert bad record mac' didn't give me anything helpful, and I hesitate to blame it on an SSL issue since the script still runs occasionally.</p>
  
  <p>I'm on Ubuntu Server 10.04, with php5 and php5-curl installed, as well as the latest version of openssl. In terms of cURL specific options, CURLOPT_SSL_VERIFYPEER is set to false, and both CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT are set to 4 seconds. Further illustrating this problem is the fact that the same exact situation occurs on my Mac OS X dev machine - the requests only go through ~50% of the time.</p>