PHP 8.4: Curl: New CURLOPT_TCP_KEEPCNT
option
The PHP 8.4 Curl extension introduces a new Curl option named CURLOPT_TCP_KEEPCNT
that sets the maximum number of TCP keep-alive probes.
The default value for this option is set to 9
, but using the CURLOPT_TCP_KEEPCNT
option, it is possible to increase or decrease the maximum number of keep-alive probes.
This option accepts any int
value of 0
or higher. Attempting to set an invalid value results in the curl_setopt
call to return false
.
Other Curl options such as CURLOPT_TCP_KEEPALIVE
, CURLOPT_TCP_KEEPIDLE
, and CURLOPT_TCP_KEEPINTVL
also provide more control over the TCP keep-alive feature.
$ch = curl_init('https://php.watch');
curl_setopt($ch, CURLOPT_TCP_KEEPCNT, 15));
curl_exec($ch);
Backward Compatibility Impact
This option is available on PHP 8.4, and if the extension is built with libcurl 8.9.0 or later. It is not possible to back-port this feature to older PHP versions.