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
Prev Previous commit
Next Next commit
added CURLINFO_CONN_ID
  • Loading branch information
thecaliskan committed Jun 30, 2025
commit 97f7af0a4240fff7be7fe79dc597c6d499561616
10 changes: 5 additions & 5 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2659,11 +2659,6 @@ 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 Expand Up @@ -2696,6 +2691,11 @@ PHP_FUNCTION(curl_getinfo)
if (curl_easy_getinfo(ch->cp, CURLINFO_PROXYAUTH_USED, &l_code) == CURLE_OK) {
CAAL("proxyauth_used", l_code);
}
#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
} else {
switch (option) {
Expand Down
33 changes: 12 additions & 21 deletions ext/curl/tests/curl_getinfo_CURLINFO_CONN_ID.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,30 @@ $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_URL, "{$host}/get.inc?test=get");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Connection: Keep-Alive',
'Keep-Alive: 10'
]);

$info = curl_getinfo($ch);
var_dump(isset($info['conn_id']));
var_dump($info['conn_id'] === 0);
var_dump("1. debug");
var_dump($info['conn_id']);
print_r($info);
var_dump($info['conn_id'] === -1);

$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['conn_id']);
var_dump(curl_getinfo($ch, CURLINFO_CONN_ID) === -1);
var_dump("2. debug");
var_dump($info['conn_id']);
print_r($info);
var_dump(curl_getinfo($ch, CURLINFO_CONN_ID) === 0);



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

$info = curl_getinfo($ch);
var_dump("3. debug");
var_dump($info['conn_id']);
print_r($info);
var_dump(isset($info['conn_id']));
var_dump(is_int($info['conn_id']));
var_dump(curl_getinfo($ch, CURLINFO_CONN_ID) === $info['conn_id']);
var_dump(curl_getinfo($ch, CURLINFO_CONN_ID) === 1);


?>
Expand All @@ -62,4 +49,8 @@ bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)