Use of undefined constant CURLOPT_TCP_FASTOPEN

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.


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

Tags:

Php

Php Curl