Skip to content

Commit 99bceda

Browse files
authored
ext/curl: Add CURLINFO_POSTTRANSFER_TIME_T support (phpGH-15849)
libcurl ref: [`CURLINFO_POSTTRANSFER_TIME_T`](https://curl.se/libcurl/c/CURLINFO_POSTTRANSFER_TIME_T.html) `CURLINFO_POSTTRANSFER_TIME_T` is a libcurl info option that returns the time it took to "post" the transfer. Available since libcurl 8.10.0 This value is also exposed as `posttransfer_time_us` in the `curl_getinfo()` return value when the `$option` parameter is not passed.
1 parent f35ad56 commit 99bceda

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

UPGRADING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ PHP 8.4 UPGRADE NOTES
309309
CURLINFO_HEADER_OUT, CURLINFO_DATA_IN, CURLINFO_DATA_OUT, CURLINFO_SSL_DATA_OUT,
310310
CURLINFO_SSL_DATA_IN constants. Once this option is set, CURLINFO_HEADER_OUT
311311
must not be set because it uses the same libcurl functionality.
312+
. curl_getinfo() function now returns "posttransfer_time_us", containing the
313+
number of microseconds from the start until the last byte is sent. When a
314+
redirect is followed, the time from each request is added together. This
315+
value can also be retrieved by passing CURLINFO_POSTTRANSFER_TIME_T to the
316+
curl_getinfo() $option parameter. This requires libcurl 8.10.0 or later.
312317

313318
- Date:
314319
. Added static methods
@@ -1055,6 +1060,7 @@ PHP 8.4 UPGRADE NOTES
10551060
. CURLINFO_DATA_OUT.
10561061
. CURLINFO_SSL_DATA_OUT.
10571062
. CURLINFO_SSL_DATA_IN.
1063+
. CURLINFO_POSTTRANSFER_TIME_T.
10581064

10591065
- Intl:
10601066
. The IntlDateFormatter class exposes now the new PATTERN constant

ext/curl/curl.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,6 +3054,13 @@
30543054
* @cvalue CURLINFO_TOTAL_TIME_T
30553055
*/
30563056
const CURLINFO_TOTAL_TIME_T = UNKNOWN;
3057+
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
3058+
/**
3059+
* @var int
3060+
* @cvalue CURLINFO_POSTTRANSFER_TIME_T
3061+
*/
3062+
const CURLINFO_POSTTRANSFER_TIME_T = UNKNOWN;
3063+
#endif
30573064
/**
30583065
* @var int
30593066
* @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
@@ -2598,6 +2598,11 @@ PHP_FUNCTION(curl_getinfo)
25982598
if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME_T, &co) == CURLE_OK) {
25992599
CAAL("starttransfer_time_us", co);
26002600
}
2601+
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
2602+
if (curl_easy_getinfo(ch->cp, CURLINFO_POSTTRANSFER_TIME_T, &co) == CURLE_OK) {
2603+
CAAL("posttransfer_time_us", co);
2604+
}
2605+
#endif
26012606
if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME_T, &co) == CURLE_OK) {
26022607
CAAL("total_time_us", co);
26032608
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Curlinfo CURLINFO_POSTTRANSFER_TIME_T
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php
7+
$curl_version = curl_version();
8+
if ($curl_version['version_number'] < 0x080a00) die("skip: test works only with curl >= 8.10.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['posttransfer_time_us']));
23+
var_dump($info['posttransfer_time_us'] === 0); // this is always 0 before executing the transfer
24+
25+
$result = curl_exec($ch);
26+
27+
$info = curl_getinfo($ch);
28+
var_dump(isset($info['posttransfer_time_us']));
29+
var_dump(is_int($info['posttransfer_time_us']));
30+
var_dump(curl_getinfo($ch, CURLINFO_POSTTRANSFER_TIME_T) === $info['posttransfer_time_us']);
31+
var_dump(curl_getinfo($ch, CURLINFO_POSTTRANSFER_TIME_T) > 0);
32+
33+
?>
34+
--EXPECT--
35+
bool(true)
36+
bool(true)
37+
bool(true)
38+
bool(true)
39+
bool(true)
40+
bool(true)
41+

0 commit comments

Comments
 (0)