cURL with HTTP/2
  • 4,202 views,
  • 2017-10-20,
  • 上傳者: Kuann Hung,
  •  0
最近弄一些一定要支援 HTTP/2 的服務,但是內建的 PHP cURL library 卻不支援!!
所以如果沒有把握你的 PHP 是否支援的話,可以用下面的語法驗證一下喔!!
 
defined('CURL_VERSION_HTTP2') || define('CURL_VERSION_HTTP2', 65536);
defined('CURL_HTTP_VERSION_2_0') || define('CURL_HTTP_VERSION_2_0', 3);
defined('CURL_HTTP_VERSION_2') || define('CURL_HTTP_VERSION_2', CURL_HTTP_VERSION_2_0);
defined('CURLPIPE_NOTHING') || define(CURLPIPE_NOTHING, 0);
defined('CURLPIPE_HTTP1') || define('CURLPIPE_HTTP1', 1);
defined('CURLPIPE_MULTIPLEX') || define('CURLPIPE_MULTIPLEX', 2);

if (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") === 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.";
}
Facebook 討論區載入中...
資料夾 :
發表時間 :
2017-10-20 19:02:54
觀看數 :
4,202
發表人 :
Kuann Hung
部門 :
老洪的 IT 學習系統
QR Code :