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 also dabbles in Ruby and Go. Technical topics that interest me are monitoring, security and performance.

During the day I solve challenging technical problems at Something Digital where I mainly work with the Magento platform. I also blog about tech, work on open source and hunt for bugs.

If you'd like to get in touch with me the best way is on Twitter.