CentOS 7 如何更新通过 yum 安装的 PHP 带的 curl 扩展??
1. 运行环境
1). 当前使用的各软件版本?
- CentOS 7
- PHP 7.4.30
- curl 7.85.0(目前最新版本)
2. 问题描述?
项目是用 Laravel
写的爬虫,运行在 CLI
模式,需要使用 HTTP2.0
协议。CentOS
自带的 curl
版本比较老,不支持 HTTP2.0
。
导致代码报错 Undefined constant 'CURL_HTTP_VERSION_2_0'
尝试用 Yum 更新 curl
后,直接用命令行是可以用 HTTP2.0
协议,但是 PHP 依然不行。
期望的结果
PHP 代码也能正常使用 curl
发出 HTTP2.0
协议的请求。
尝试过的方法
通过 yum 升级 libcurl
后,使用命令验证,可以看到已经支持 HTTP2.0
了。
curl -V
curl 7.85.0 (x86_64-redhat-linux-gnu) libcurl/7.85.0 NSS/3.53.1 zlib/1.2.7 libpsl/0.20.2 (+libidn2/2.3.2) libssh2/1.10.0 nghttp2/1.33.0
Release-Date: 2022-08-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB PSL SPNEGO SSL UnixSockets
实际请求一下也是支持的。
curl --http2 -I https://nghttp2.org
HTTP/2 200
date: xxx, xx Sep 2022 xx:xx:xx GMT
content-type: text/html
last-modified: xxx, xx xxx 2022 xx:xx:xx GMT
etag: "xxxxxbb0-18b4"
accept-ranges: bytes
content-length: 6324
x-backend-header-rtt: 0.006897
strict-transport-security: max-age=31536000
server: nghttpx
alt-svc: h3=":443"; ma=3600, h3-29=":443"; ma=3600
via: 2 nghttpx
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
不过 phpinfo()
虽然显示了正确的版本,却依然没有 HTTP2.0
,与此对比,Homestead
里面的 PHP 就有 HTTP2 => Yes
。
下面是 CentOS 7
里面的 php -i
curl
cURL support => enabled
cURL Information => 7.85.0
Age => 9
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => No
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => Yes
SSL => Yes
SSPI => No
TLS-SRP => No
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => x86_64-redhat-linux-gnu
SSL Version => NSS/3.53.1
ZLib Version => 1.2.7
libSSH Version => libssh2/1.10.0
Directive => Local Value => Master Value
curl.cainfo => no value => no value
推测是因为 PHP 的 curl.so
扩展没有更新的原因,但是这台服务器的 PHP 是通过 yum
安装的 remi 源
多版本共存,不知道应该怎么更新 curl.so
扩展。大佬们有没有办法更新这个扩展呢?
提前感谢各位大佬赐教。
重新编译 php 的 curl 扩展不就行了?