0

I got this error. Any idea?

Thank you.

Error:

PHP Fatal error:  Uncaught Error: Undefined constant "CURLOPT_TCP_FASTOPEN"

OS:

CentOs 7.x

Version:

3.10.0-1160.76.1.el7.x86_64

$curl --tcp-fastopen -O http://google.com

curl: option --tcp-fastopen: is unknown
curl: try 'curl --help' or 'curl --manual' for more information

$ php -v

PHP 8.1.12 (cli) (built: Oct 25 2022 17:30:00) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies

$cat /proc/sys/net/ipv4/tcp_fastopen

3

PHP has been installed using:

sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php81
sudo yum repolist
sudo yum -y install php php-{cli,mbstring,curl,json}

php.ini

cURL support => enabled
cURL Information => 7.29.0
Age => 3
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => Yes
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => No
SSL => Yes
SSPI => No
TLS-SRP => No
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, scp, sftp, 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.8.0
  • You might want to look at https://stackoverflow.com/questions/61650504/use-of-undefined-constant-curlopt-tcp-fastopen/61756687#61756687 – Progman Nov 14 '22 at 18:27
  • Does this answer your question? [Use of undefined constant CURLOPT\_TCP\_FASTOPEN](https://stackoverflow.com/questions/61650504/use-of-undefined-constant-curlopt-tcp-fastopen) – Martin Nov 15 '22 at 10:56
  • Looks like you need to install or update your version of cURL – Martin Nov 15 '22 at 10:56

2 Answers2

1

You are using CentOS 7 which is more than 8 years old, and is close to its end of life (in June 2024).

I heartily recommend to use a more recent distribution version (8 or 9), especially for modern features.

CURLOPT_TCP_FASTOPEN was introduced in curl 7.49

  • EL-7 have 7.19
  • EL-8 have 7.61
  • EL-9 have 7.76

So you cannot fix this error in EL-7 without rebuilding nearly everything.

Remi Collet
  • 6,198
  • 1
  • 20
  • 25
  • CentOS 8/9 is an absolute traincrash and not recommended. CentOS 8 was withdrawn in 2021 and superceded by CentOS 9 which is "Stream" version and is in a state of "constant-beta" development meaning it is and is going to be an utter mess. – Martin Nov 15 '22 at 10:55
  • Not true, both CentOS 8 Stream and CentOS 9 Stream exist (too much FUD about this) And other clones (Alma, Rocky...) and even RHEL (free subs.) – Remi Collet Nov 15 '22 at 11:44
  • On CentOS 8 and Ubuntu 20 works. CentOS as least "curl --tcp-fastopen -O http://google.com". Alma is perfect choise but it is not on the list, yet. I have tiried upgrade from CentOS 8 to Alma but a lot of problem - it is already EOF. – Staš Repše Nov 16 '22 at 18:12
0

CURLOPT_TCP_FASTOPEN requires libcurl 7.49.0 or newer, while your PHP is compiled against libcurl 7.29.0. upgrade your libcurl and compile php again.

maybe try

git clone -b 'OpenSSL_1_1_1k' --single-branch --depth 1 https://github.com/openssl/openssl
cd openssl
./config
make -j $(nproc)
mkdir lib
cp *.a lib;
cd ..
git clone -b 'curl-7_76_1' --single-branch --depth 1 https://github.com/curl/curl.git
cd curl
./buildconf
LDFLAGS="-static" ./configure --with-ssl=$(realpath ../openssl) --enable-static
make -j $(nproc)
cd ..
git clone -b 'PHP-8.1' --single-branch --depth 1 'https://github.com/php/php-src.git'
cd php-src;
./buildconf;
./configure --with-curl=$(realpath ../curl)
make -j $(nproc)
hanshenrik
  • 19,904
  • 4
  • 43
  • 89
  • Thank you very much. I tried. I got a lot of errors but still new errors appears. Executed on fresh OS. Missing libaries: yum install get gcc autoconf automake libtool gobjc++ – Staš Repše Nov 16 '22 at 18:09