mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
ext/curl: Add CURLINFO_POSTTRANSFER_TIME_T support (GH-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.
This commit is contained in:
committed by
GitHub
parent
f35ad560b4
commit
99bceda0b3
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -3054,6 +3054,13 @@ const CURLINFO_STARTTRANSFER_TIME_T = UNKNOWN;
|
||||
* @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
|
||||
|
||||
5
ext/curl/curl_arginfo.h
generated
5
ext/curl/curl_arginfo.h
generated
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: c5e16a7da3f25d061813235a262501e0d8747ccb */
|
||||
* Stub hash: 6a6a7461b475bb10cef3048ee2c11ab0dd32f328 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_close, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
|
||||
@@ -799,6 +799,9 @@ static void register_curl_symbols(int module_number)
|
||||
REGISTER_LONG_CONSTANT("CURLINFO_REDIRECT_TIME_T", CURLINFO_REDIRECT_TIME_T, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("CURLINFO_STARTTRANSFER_TIME_T", CURLINFO_STARTTRANSFER_TIME_T, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("CURLINFO_TOTAL_TIME_T", CURLINFO_TOTAL_TIME_T, CONST_PERSISTENT);
|
||||
#if LIBCURL_VERSION_NUM >= 0x080a00 /* Available since 8.10.0 */
|
||||
REGISTER_LONG_CONSTANT("CURLINFO_POSTTRANSFER_TIME_T", CURLINFO_POSTTRANSFER_TIME_T, CONST_PERSISTENT);
|
||||
#endif
|
||||
REGISTER_LONG_CONSTANT("CURLOPT_DISALLOW_USERNAME_IN_URL", CURLOPT_DISALLOW_USERNAME_IN_URL, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("CURLOPT_PROXY_TLS13_CIPHERS", CURLOPT_PROXY_TLS13_CIPHERS, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("CURLOPT_TLS13_CIPHERS", CURLOPT_TLS13_CIPHERS, CONST_PERSISTENT);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user