Skip to content

Add support for CURLINFO_CONN_ID in curl_getinfo() #18984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Next Next commit
added CURLINFO_CONN_ID
  • Loading branch information
thecaliskan committed Jun 30, 2025
commit 89496808f06f91ac6da172eafc90c152804a3d20
6 changes: 6 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ PHP 8.5 UPGRADE NOTES
first redirect thus if there is any follow up redirect, it won't go
any further. CURLFOLLOW_ALL is equivalent to setting CURLOPT_FOLLOWLOCATION
to true.
. Added support for CURLINFO_CONN_ID (libcurl >= 8.2.0) to the curl_getinfo()
function. This constant allows retrieving the unique ID of the connection
used by a cURL transfer. It is primarily useful when connection reuse or
connection pooling logic is needed in PHP-level applications. When
curl_getinfo() returns an array, this value is available as the "conn_id" key.

- DOM:
. Added Dom\Element::$outerHTML.
Expand Down Expand Up @@ -483,6 +488,7 @@ PHP 8.5 UPGRADE NOTES
. CURLINFO_USED_PROXY.
. CURLINFO_HTTPAUTH_USED.
. CURLINFO_PROXYAUTH_USED.
. CURLINFO_CONN_ID.
. CURLOPT_INFILESIZE_LARGE.
. CURLFOLLOW_ALL.
. CURLFOLLOW_OBEYCODE.
Expand Down
7 changes: 7 additions & 0 deletions ext/curl/curl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3103,6 +3103,13 @@
*/
const CURLINFO_POSTTRANSFER_TIME_T = UNKNOWN;
#endif
#if LIBCURL_VERSION_NUM >= 0x080200 /* Available since 8.2.0 */
/**
* @var int
* @cvalue CURLINFO_CONN_ID
*/
const CURLINFO_CONN_ID = UNKNOWN;
#endif
/**
* @var int
* @cvalue CURLOPT_DISALLOW_USERNAME_IN_URL
Expand Down
5 changes: 4 additions & 1 deletion ext/curl/curl_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,11 @@ PHP_FUNCTION(curl_getinfo)
if (curl_easy_getinfo(ch->cp, CURLINFO_POSTTRANSFER_TIME_T, &co) == CURLE_OK) {
CAAL("posttransfer_time_us", co);
}
#endif
#if LIBCURL_VERSION_NUM >= 0x080200 /* Available since 8.2.0 */
if (curl_easy_getinfo(ch->cp, CURLINFO_CONN_ID , &co) == CURLE_OK) {
CAAL("conn_id", co);
}
#endif
if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME_T, &co) == CURLE_OK) {
CAAL("total_time_us", co);
Expand Down
39 changes: 39 additions & 0 deletions ext/curl/tests/curl_getinfo_CURLINFO_CONN_ID.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Curlinfo CURLINFO_CONN_ID
--EXTENSIONS--
curl
--SKIPIF--
<?php
$curl_version = curl_version();
if ($curl_version['version_number'] < 0x080200) die("skip: test works only with curl >= 8.2.0");
?>
--FILE--
<?php
include 'server.inc';

$host = curl_cli_server_start();
$port = (int) (explode(':', $host))[1];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=file");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$info = curl_getinfo($ch);
var_dump(isset($info['conn_id']));

$result = curl_exec($ch);

$info = curl_getinfo($ch);
var_dump(isset($info['conn_id']));
var_dump(is_int($info['conn_id']));
var_dump(curl_getinfo($ch, CURLINFO_CONN_ID) === $info['CURLINFO_CONN_ID']);
var_dump(curl_getinfo($ch, CURLINFO_CONN_ID) > 0);

?>
--EXPECT--
bool(false)
bool(true)
bool(true)
bool(true)
bool(true)

Loading