Skip to content

Commit 3d26eb6

Browse files
committed
ext/curl: Add CURLINFO_POSTTRANSFER_TIME_T support
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 adfd7de commit 3d26eb6

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
@@ -298,6 +298,11 @@ PHP 8.4 UPGRADE NOTES
298298
to allow or abort the request.
299299
. Added CURLOPT_SERVER_RESPONSE_TIMEOUT, which was formerly known as
300300
CURLOPT_FTP_RESPONSE_TIMEOUT. Both constants hold the same value.
301+
. curl_getinfo() function now returns "posttransfer_time_us", containing the
302+
number of microseconds from the start until the last byte is sent. When a
303+
redirect is followed, the time from each request is added together. This
304+
value can also be retrieved by passing CURLINFO_POSTTRANSFER_TIME_T to the
305+
curl_getinfo() $option parameter. This requires libcurl 8.10.0 or later.
301306

302307
- Date:
303308
. Added static methods
@@ -1028,6 +1033,7 @@ PHP 8.4 UPGRADE NOTES
10281033
. CURL_PREREQFUNC_OK.
10291034
. CURL_PREREQFUNC_ABORT.
10301035
. CURLOPT_SERVER_RESPONSE_TIMEOUT.
1036+
. CURLINFO_POSTTRANSFER_TIME_T.
10311037

10321038
- Intl:
10331039
. 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
@@ -3012,6 +3012,13 @@
30123012
* @cvalue CURLINFO_TOTAL_TIME_T
30133013
*/
30143014
const CURLINFO_TOTAL_TIME_T = UNKNOWN;
3015+
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
3016+
/**
3017+
* @var int
3018+
* @cvalue CURLINFO_POSTTRANSFER_TIME_T
3019+
*/
3020+
const CURLINFO_POSTTRANSFER_TIME_T = UNKNOWN;
3021+
#endif
30153022
/**
30163023
* @var int
30173024
* @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
@@ -2557,6 +2557,11 @@ PHP_FUNCTION(curl_getinfo)
25572557
if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME_T, &co) == CURLE_OK) {
25582558
CAAL("starttransfer_time_us", co);
25592559
}
2560+
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
2561+
if (curl_easy_getinfo(ch->cp, CURLINFO_POSTTRANSFER_TIME_T, &co) == CURLE_OK) {
2562+
CAAL("posttransfer_time_us", co);
2563+
}
2564+
#endif
25602565
if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME_T, &co) == CURLE_OK) {
25612566
CAAL("total_time_us", co);
25622567
}
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)