true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS, CURLOPT_TIMEOUT => 15, CURLOPT_USERAGENT => 'ExampleHttp2Client/1.0', ]); $body = curl_exec($curl); if ($body === false) { fwrite(STDERR, 'cURL error: ' . curl_error($curl) . PHP_EOL); curl_close($curl); exit(1); } $status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE); $httpVersion = curl_getinfo($curl, CURLINFO_HTTP_VERSION); curl_close($curl); $versionNames = []; foreach ([ 'CURL_HTTP_VERSION_1_0' => 'HTTP/1.0', 'CURL_HTTP_VERSION_1_1' => 'HTTP/1.1', 'CURL_HTTP_VERSION_2_0' => 'HTTP/2', 'CURL_HTTP_VERSION_2' => 'HTTP/2', 'CURL_HTTP_VERSION_2TLS' => 'HTTP/2', ] as $constant => $label) { if (defined($constant)) { $versionNames[constant($constant)] = $label; } } $negotiated = $versionNames[$httpVersion] ?? 'unknown'; echo 'HTTP status: ' . $status . PHP_EOL; echo 'Negotiated protocol: ' . $negotiated . PHP_EOL; if ($status < 200 || $status >= 300 || $negotiated !== 'HTTP/2') { fwrite(STDERR, 'The request did not complete over HTTP/2.' . PHP_EOL); exit(1); }