Is there a way to force PHP to make a HTTP2 connection to another server just to see if that server supports it?
I\'ve tried:
$options = stream_conte
As far as I'm aware, cURL is the only transfer method in PHP that supports HTTP 2.0.
You'll first need to test that your version of cURL can support it, and then set the correct version header:
if (
defined("CURL_VERSION_HTTP2") &&
(curl_version()["features"] & CURL_VERSION_HTTP2) !== 0
) {
$url = "https://www.google.com/";
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL =>$url,
CURLOPT_HEADER =>true,
CURLOPT_NOBODY =>true,
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_HTTP_VERSION =>CURL_HTTP_VERSION_2_0,
]);
$response = curl_exec($ch);
if ($response !== false && strpos($response, "HTTP/2") === 0) {
echo "HTTP/2 support!";
} elseif ($response !== false) {
echo "No HTTP/2 support on server.";
} else {
echo curl_error($ch);
}
curl_close($ch);
} else {
echo "No HTTP/2 support on client.";
}