Symptom: php curl calls https error
Troubleshooting method: Try using curl call in the command line.
Cause: The computer room where the server is located cannot verify the SSL certificate.
Workaround: Skip SSL certificate check.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Symptom: php curl calls curl_exec to return bool (false), and the command line curl call is normal.
Troubleshooting method:
var_dump(curl_error($ch));
Return:
string(23) "Empty reply from server"
Troubleshoot again :
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
Return:
HTTP/1.1 100 Continue
Connection: close
Cause: php curl ends after receiving HTTP 100, and should continue to receive HTTP 200
Solution:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(' Expect:'));
PHP and cURL: Disabling 100-continue header
Published June 15th, 2006
I've been using cURL (through PHP) to build a sort of proxy for a project I'm working on. I need to parse the returned headers (to recover the HTTP status), so had included a very simple script to do so. It had worked fine in the past, but for some reason barfed in this case. A closer look at what was being returned revealed that for some reason, Apache was prepending the 'normal' headers with an extra response header:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK Date: Fri, 09 Jun 2006 15:23:42 GMT
Server: Apache
...A bit of Googling revealed that this was to do with a header that cURL sends by default:
Expect: 100-continue
…which in turns tells Apache to send the extra header. I poked around a fair bit but couldn't quite find a workable solution short of manually removing the header in PHP, which seemed a bit clumsy. Finally, on a hunch I tried this:
curl_setopt( $curl_handle, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
…which basically overrides the original 'Expect:' header with an empty one.
Hope this helps someone.