3

Can I curl a website that supports HTTP/3, with curl, using HTTP/3 instead of HTTP/2, HTTP/1.1 or HTTP/1.0. Is this possible? If so, how to do this?

TylerH
  • 19,065
  • 49
  • 65
  • 86
Example person
  • 2,093
  • 2
  • 8
  • 31
  • Did you read https://github.com/curl/curl/wiki/HTTP3 or https://daniel.haxx.se/blog/2019/08/05/first-http-3-with-curl/ (both at the top of Google results for "curl http/3")? – Joseph Sible-Reinstate Monica Feb 18 '20 at 05:16
  • I see that it is introduced to curl, but how do I use it in PHP? What is the curl option I should use to enable it? – Example person Feb 18 '20 at 05:20
  • Here is an code example (I don't guarantee if this will work): https://gist.github.com/bagder/a88d3bedc8ecb69d19aeb542fa538e9b. You need to make sure, that your curl version is build with HTTP3 support! – CodyKL Feb 18 '20 at 05:38

1 Answers1

5

Yes it is indeed possible to get going but you need tweaks and manual hands-on to make it work:

  1. Make sure your PHP uses a libcurl built to support HTTP/3

  2. Provide the necessary HTTP3 symbol for your PHP program, perhaps like the example below (as CURL/PHP itself doesn't know about HTTP/3 yet)

  3. Make sure that the QUIC/h3 libraries you build curl to use support the same HTTP/3 draft version as the test server you intend to try out

  4. HTTP/3 and QUIC are not done yet, expect rough edges and glitches. Enable verbose and keep attention to details

Happy http3ing!

if (!defined('CURL_HTTP_VERSION_3')) {
  define('CURL_HTTP_VERSION_3', 30);
}
    
$ch = curl_init("https://cloudflare-quic.com/");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3);
curl_exec($ch);
Daniel Stenberg
  • 44,219
  • 12
  • 115
  • 175
  • I understand now. I tested it already and it worked, but forgot about updating. Thanks a lot. I see that libcurl in Ubuntu 19.10 is not compatible with HTTP/3, so I am sorry for mentioning that it is not possible in one of my comments. – Example person Feb 18 '20 at 10:22