如果我CURLOPT_TCP_FASTOPEN在代码中使用该选项,则会出现以下错误。
使用未定义的常量 CURLOPT_TCP_FASTOPEN - 假设为 'CURLOPT_TCP_FASTOPEN'
CURLOPT_TCP_FASTOPEN 是 php 7.4.5 interface 中支持的选项。
php -v
PHP 7.4.5 (cli) (built: Apr 14 2020 12:54:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies
Run Code Online (Sandbox Code Playgroud)
卷曲 -V
curl 7.70.0 (x86_64-redhat-linux-gnu) libcurl/7.70.0 NSS/3.44 zlib/1.2.7 libpsl/0.7.0 (+libicu/50.1.2) libssh2/1.9.0 nghttp2/1.31.1
Release-Date: 2020-04-29
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz Metalink NTLM NTLM_WB PSL SPNEGO SSL UnixSockets
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
编辑1:
以下是与 YouriKoeman 概述相对应的附加信息
内核版本:3.10.0-1062.12.1.el7.x86_64
操作系统:unix (Centos 7.x)
curl --tcp-fastopen -L http://www.google.com 返回以下错误:
curl: (55) Send failure: Operation not supported for curl --tcp-fastopen -L http://www.google.com
小智 9
我选择以更广泛的方式回答,希望能在遇到与此相关的问题时帮助更多人并谷歌寻求答案
(注意:php 运行时和加载的扩展在 CLI 和从网络服务器访问时可能不同)。
CURLOPT_TCP_FASTOPEN您要使用的功能有一些必须满足的系统要求
它们如下:
Kernel version > 3.6 (linux)PHP 7.0.7或更高Curl(program) AND php{your/version}-curl 7.49.0或更高*nix操作系统(macos、linux、bsd)未定义常量的事实是不满足这些依赖项之一的危险信号,但我如何确定哪个依赖项?
这一个是容易的,运行以下命令:
uname -r。
它必须大于 3.6
检查 curl 中该功能是否可用的最佳方法是使用此选项从 cli 调用 curl,例如:
curl --tcp-fastopen -O http://google.com
如果此请求成功,则说明您的系统上正确配置了 curl,因此问题出在 php 中
用于phpinfo()检查 是否php version大于7.0.7并且php-curl加载了扩展
在命令行类型中php -v,版本应该大于7.0.7.
要检查扩展,请在命令行中键入以下命令,php -m | grep curl此命令应返回curl,如果未返回任何内容,则不会为 php cli 加载 curl 扩展。
问题是在内核版本 3.13 之前默认情况下不启用 tcp 快速打开。
在 Centos 7 上启用 TCP Fast Open:
1.在sysctl.d中添加tcp_fastopen
echo "net.ipv4.tcp_fastopen=3" > /etc/sysctl.d/30-tcp_fastopen.conf
Run Code Online (Sandbox Code Playgroud)
2.重启sysctl
systemctl restart systemd-sysctl
Run Code Online (Sandbox Code Playgroud)
3.验证 tcp_fastopen 的 sysctl 设置
cat /proc/sys/net/ipv4/tcp_fastopen 应该输出 3