skip to Main Content

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


  1. Chosen as BEST ANSWER

    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

    echo "net.ipv4.tcp_fastopen=3" > /etc/sysctl.d/30-tcp_fastopen.conf 
    

    2.Restart sysctl

    systemctl restart systemd-sysctl
    

    3.Verify sysctl setup for tcp_fastopen

    cat /proc/sys/net/ipv4/tcp_fastopen should output 3


  2. I chose to answer in a more broad way to hopefully help more poeple when they encounter issues relating to this and google for answers

    (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 met

    They are the following:

    1. You must have Kernel version > 3.6 (linux)
    2. You must have PHP 7.0.7 or higher
    3. You must have Curl(program) AND php{your/version}-curl 7.49.0 or higher
    4. You must have a *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 the php version is greater than 7.0.7 And that the php-curl extensions are loaded

    For CLI

    in the command line type php -v the version should be greater than 7.0.7.

    To check the extensions type the following into your command line php -m | grep curl this command should return curl, if nothing is returned the curl extension is not loaded for the php cli.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search