Skip to content

ext/curl: Add CURLINFO_POSTTRANSFER_TIME_T support #15849

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

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ PHP 8.4 UPGRADE NOTES
CURLINFO_HEADER_OUT, CURLINFO_DATA_IN, CURLINFO_DATA_OUT, CURLINFO_SSL_DATA_OUT,
CURLINFO_SSL_DATA_IN constants. Once this option is set, CURLINFO_HEADER_OUT
must not be set because it uses the same libcurl functionality.
. curl_getinfo() function now returns "posttransfer_time_us", containing the
number of microseconds from the start until the last byte is sent. When a
redirect is followed, the time from each request is added together. This
value can also be retrieved by passing CURLINFO_POSTTRANSFER_TIME_T to the
curl_getinfo() $option parameter. This requires libcurl 8.10.0 or later.

- Date:
. Added static methods
Expand Down Expand Up @@ -1055,6 +1060,7 @@ PHP 8.4 UPGRADE NOTES
. CURLINFO_DATA_OUT.
. CURLINFO_SSL_DATA_OUT.
. CURLINFO_SSL_DATA_IN.
. CURLINFO_POSTTRANSFER_TIME_T.

- Intl:
. The IntlDateFormatter class exposes now the new PATTERN constant
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 @@ -3054,6 +3054,13 @@
* @cvalue CURLINFO_TOTAL_TIME_T
*/
const CURLINFO_TOTAL_TIME_T = UNKNOWN;
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
/**
* @var int
* @cvalue CURLINFO_POSTTRANSFER_TIME_T
*/
const CURLINFO_POSTTRANSFER_TIME_T = 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 @@ -2598,6 +2598,11 @@ PHP_FUNCTION(curl_getinfo)
if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME_T, &co) == CURLE_OK) {
CAAL("starttransfer_time_us", co);
}
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
if (curl_easy_getinfo(ch->cp, CURLINFO_POSTTRANSFER_TIME_T, &co) == CURLE_OK) {
CAAL("posttransfer_time_us", co);
}
#endif
if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME_T, &co) == CURLE_OK) {
CAAL("total_time_us", co);
}
Expand Down
41 changes: 41 additions & 0 deletions ext/curl/tests/curl_getinfo_CURLINFO_POSTTRANSFER_TIME_T.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
Curlinfo CURLINFO_POSTTRANSFER_TIME_T
--EXTENSIONS--
curl
--SKIPIF--
<?php
$curl_version = curl_version();
if ($curl_version['version_number'] < 0x080a00) die("skip: test works only with curl >= 8.10.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['posttransfer_time_us']));
var_dump($info['posttransfer_time_us'] === 0); // this is always 0 before executing the transfer

$result = curl_exec($ch);

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

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

Loading