If i use the CURLOPT_TCP_FASTOPEN
option in my code , then i get the following error.
Use of undefined constant CURLOPT_TCP_FASTOPEN – assumed
‘CURLOPT_TCP_FASTOPEN’
The CURLOPT_TCP_FASTOPEN is a supported option in 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
curl -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
What am i doing wrong here ?
Edit 1:
Here are additional info corresponding to YouriKoeman’s overview
Kernel version : 3.10.0-1062.12.1.el7.x86_64
OS : unix (Centos 7.x)
curl --tcp-fastopen -L http://www.google.com
return the following error:
curl: (55) Send failure: Operation not supported for curl --tcp-fastopen -L http://www.google.com
2
Answers
The issue was that tcp fast open is not enabled by default until kernel version 3.13.
To enable TCP Fast Open on Centos 7:
1.Add tcp_fastopen in sysctl.d
2.Restart sysctl
3.Verify sysctl setup for tcp_fastopen
cat /proc/sys/net/ipv4/tcp_fastopen
should output 3(Note: php runtime and Loaded extensions can differ between the CLI and when accessed from a webserver).
What are the system requirements for this feature?
The feature
CURLOPT_TCP_FASTOPEN
you want to use has some system requirements that have to be metThey are the following:
Kernel version > 3.6 (linux)
PHP 7.0.7
or higherCurl(program) AND php{your/version}-curl 7.49.0
or higher*nix
type of operating system (macos, linux, bsd)how to debug What requirement is not being met?
The fact that the constant is not defined is a red flag that one of these dependencies is not met, but how do i figure out which?
kernel version
This one is easy, run the following command:
uname -r
.It must be greater than
3.6
Curl version and build options
The best way to check if the functionality is available in curl is to call curl from the cli with this option, like:
curl --tcp-fastopen -O http://google.com
If this request goes successfully, curl is configured correctly on your system, so the problem lies within php
PHP version and extensions
For webserver
use
phpinfo()
to check if thephp version
is greater than7.0.7
And that thephp-curl
extensions are loadedFor CLI
in the command line type
php -v
the version should be greater than7.0.7
.To check the extensions type the following into your command line
php -m | grep curl
this command should returncurl
, if nothing is returned the curl extension is not loaded for the php cli.