GuzzleHttp\Exception\ConnectException:cURL 错误 1:协议 "http2" 不受支持或在 libcurl 中被禁用(请参阅 https://curl.haxx.se/libcurl/c/libcurl-errors.html),位于 /var/www/app/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:187
GuzzleHttp\Exception\ConnectException: cURL error 1: Protocol "http2" not supported or disabled in libcurl (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in /var/www/app/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:187
ID: php/guzzle-http-version-not-supported
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Guzzle 7.0 | active | — | — | — |
| Guzzle 7.5 | active | — | — | — |
| PHP 8.1 | active | — | — | — |
| PHP 8.2 | active | — | — | — |
根因分析
安装的 libcurl 版本不支持 HTTP/2,但 Guzzle 客户端被配置为使用 'http2' 作为协议版本。
English
The installed libcurl version does not support HTTP/2, but the Guzzle client is configured to use 'http2' as the protocol version.
官方文档
https://docs.guzzlephp.org/en/stable/request-options.html#version解决方案
-
Downgrade the Guzzle client to use HTTP/1.1 instead: `$client = new GuzzleHttp\Client(['version' => '1.1']);`
-
Upgrade libcurl to a version that supports HTTP/2. On Ubuntu/Debian: `sudo apt-get update && sudo apt-get install --only-upgrade libcurl4-openssl-dev` and then recompile PHP's cURL extension. Verify with `php -i | grep cURL` and check 'cURL Information' for HTTP2 support.
无效尝试
常见但无效的做法:
-
Setting CURLOPT_HTTP_VERSION to CURL_HTTP_VERSION_2_0 manually in a custom handler
95% 失败
This does not fix the underlying libcurl limitation; it just changes the constant used, but libcurl still cannot negotiate HTTP/2.
-
Reinstalling PHP and cURL extension via apt-get without checking the libcurl version
70% 失败
The default system libcurl on older OS versions may still lack HTTP/2 support; you need to ensure the libcurl-dev package is from a version that supports HTTP/2 (e.g., >= 7.50.0).