Bars Icon

HTTP/3 Request with PHP Curl Extension

By Akash
on 31-10-2023 11:09 AM

HTTP/3 is the third major version of HTTP, and is based on QUIC. Unlike HTTP/1.1 and HTTP/2 which relied on TCP, HTTP/3 is based on a multiplexed UDP protocol named QUIC. HTTP/3, along with TLS 1.3, can provide huge performance and latency improvements. Although HTTP/3 changes a lot of transport layer semantics (e.g. the shift from TCP to UDP), the HTTP semantics of request headers, request methods, responses, and status codes.

HTTP/3 is now supported in all major browsers, while HTTP clients and web servers such as Curl, Nginx, and Litespeed provide experimental support. Caddy Server even has HTTP/3 support enabled by default. Making use of the experimental HTTP/3 support available in Curl, PHP’s Curl extension can be built with HTTP/3 support. This article explains how to compile the PHP Curl extension and its dependencies with HTTP/3 support, and how to make HTTP/3 requests with PHP.
Curl has an option named CURLOPT_HTTP_VERSION, that can be used to set the HTTP versions that can be used in the HTTP request by the Curl handler. By default, current Curl builds default to HTTP/2 with HTTP/1.1 fallback. If the web server does not support HTTP/2, Curl will seamlessly use HTTP/1.1.
For HTTP/3, Curl behaves the same way. Curl has an approach called HTTPS Eyeballing, that attempts to establish a QUIC handshake but with a 200ms hard timeout. This ensures that HTTP/3 will be used if the connection is fast enough, but does not have any major impact on requests that do not utilize HTTP/3.