Forcing HTTP Version with PHP cURL

Published: January 8, 2020

Tags:

A colleague recently reported a strange bug to me:

I’m troubleshooting an issue where data fails to sync the a 3rd party and I’ve identified this error when curl_exec runs

HTTP2 framing layer error

From what I gather online is that this typically a somewhat generic error and could have multiple causes.

My gut was that this was potentially an internal bug with the curl that was being used. As a temporary workaround I thought it would be interesting to see if it was possible to force the request to go over HTTP/1.1.

It took a bit of Googling but I was ultimately able to find CURLOPT_HTTP_VERSION in the curl documentation.

In PHP, this can be set as follows:

curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

Adding this code worked as a temporary fix for the issue my colleague was experiencing.

Max Chadwick Hi, I'm Max!

I'm a software developer who mainly works in PHP, but loves dabbling in other languages like Go and Ruby. Technical topics that interest me are monitoring, security and performance. I'm also a stickler for good documentation and clear technical writing.

During the day I lead a team of developers and solve challenging technical problems at Rightpoint where I mainly work with the Magento platform. I've also spoken at a number of events.

In my spare time I blog about tech, work on open source and participate in bug bounty programs.

If you'd like to get in contact, you can find me on Twitter and LinkedIn.