Skip to content

Commit 8949680

Browse files
committed
added CURLINFO_CONN_ID
1 parent 4a98b36 commit 8949680

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

UPGRADING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ PHP 8.5 UPGRADE NOTES
182182
first redirect thus if there is any follow up redirect, it won't go
183183
any further. CURLFOLLOW_ALL is equivalent to setting CURLOPT_FOLLOWLOCATION
184184
to true.
185+
. Added support for CURLINFO_CONN_ID (libcurl >= 8.2.0) to the curl_getinfo()
186+
function. This constant allows retrieving the unique ID of the connection
187+
used by a cURL transfer. It is primarily useful when connection reuse or
188+
connection pooling logic is needed in PHP-level applications. When
189+
curl_getinfo() returns an array, this value is available as the "conn_id" key.
185190

186191
- DOM:
187192
. Added Dom\Element::$outerHTML.
@@ -483,6 +488,7 @@ PHP 8.5 UPGRADE NOTES
483488
. CURLINFO_USED_PROXY.
484489
. CURLINFO_HTTPAUTH_USED.
485490
. CURLINFO_PROXYAUTH_USED.
491+
. CURLINFO_CONN_ID.
486492
. CURLOPT_INFILESIZE_LARGE.
487493
. CURLFOLLOW_ALL.
488494
. CURLFOLLOW_OBEYCODE.

ext/curl/curl.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,6 +3103,13 @@
31033103
*/
31043104
const CURLINFO_POSTTRANSFER_TIME_T = UNKNOWN;
31053105
#endif
3106+
#if LIBCURL_VERSION_NUM >= 0x080200 /* Available since 8.2.0 */
3107+
/**
3108+
* @var int
3109+
* @cvalue CURLINFO_CONN_ID
3110+
*/
3111+
const CURLINFO_CONN_ID = UNKNOWN;
3112+
#endif
31063113
/**
31073114
* @var int
31083115
* @cvalue CURLOPT_DISALLOW_USERNAME_IN_URL

ext/curl/curl_arginfo.h

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/curl/interface.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,11 @@ PHP_FUNCTION(curl_getinfo)
26592659
if (curl_easy_getinfo(ch->cp, CURLINFO_POSTTRANSFER_TIME_T, &co) == CURLE_OK) {
26602660
CAAL("posttransfer_time_us", co);
26612661
}
2662+
#endif
2663+
#if LIBCURL_VERSION_NUM >= 0x080200 /* Available since 8.2.0 */
2664+
if (curl_easy_getinfo(ch->cp, CURLINFO_CONN_ID , &co) == CURLE_OK) {
2665+
CAAL("conn_id", co);
2666+
}
26622667
#endif
26632668
if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME_T, &co) == CURLE_OK) {
26642669
CAAL("total_time_us", co);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Curlinfo CURLINFO_CONN_ID
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php
7+
$curl_version = curl_version();
8+
if ($curl_version['version_number'] < 0x080200) die("skip: test works only with curl >= 8.2.0");
9+
?>
10+
--FILE--
11+
<?php
12+
include 'server.inc';
13+
14+
$host = curl_cli_server_start();
15+
$port = (int) (explode(':', $host))[1];
16+
17+
$ch = curl_init();
18+
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=file");
19+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
20+
21+
$info = curl_getinfo($ch);
22+
var_dump(isset($info['conn_id']));
23+
24+
$result = curl_exec($ch);
25+
26+
$info = curl_getinfo($ch);
27+
var_dump(isset($info['conn_id']));
28+
var_dump(is_int($info['conn_id']));
29+
var_dump(curl_getinfo($ch, CURLINFO_CONN_ID) === $info['CURLINFO_CONN_ID']);
30+
var_dump(curl_getinfo($ch, CURLINFO_CONN_ID) > 0);
31+
32+
?>
33+
--EXPECT--
34+
bool(false)
35+
bool(true)
36+
bool(true)
37+
bool(true)
38+
bool(true)
39+

0 commit comments

Comments
 (0)