Skip to content

Commit fd8eaaf

Browse files
committed
ext/curl: add support for CURLINFO_SIZE_DELIVERED (libcurl >= 8.20.0)
Adds support for `CURLINFO_SIZE_DELIVERED`[^1] when built with libcurl >= 8.20.0. In `curl_getinfo()`, the `size_delivered` key or the direct return value when the `$option` parameter is set to `CURLINFO_SIZE_DELIVERED` returns the number of bytes delivered. For transfers that do not use compression (`CURLOPT_ACCEPT_ENCODING`), this value will be the same as `CURLINFO_SIZE_DOWNLOAD`. For encoded transfers, the `CURLINFO_SIZE_DELIVERED` value will be the uncompressed size while `CURLINFO_SIZE_DOWNLOAD` will be the compressed size over network. [^1]: https://github.com/curl/curl/blob/curl-8_20_0/docs/libcurl/opts/CURLINFO_SIZE_DELIVERED.md Closes GH-22408.
1 parent 6f0aa11 commit fd8eaaf

6 files changed

Lines changed: 69 additions & 1 deletion

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ PHP NEWS
3737
- BZ2:
3838
. Reject oversized input in bzdecompress(). (arshidkv12)
3939

40+
- Curl:
41+
. Add support for CURLINFO_SIZE_DELIVERED (libcurl >= 8.20.0). (Ayesh)
42+
4043
- Date:
4144
. Update timelib to 2022.16. (Derick)
4245

UPGRADING

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ PHP 8.6 UPGRADE NOTES
186186
. It is now possible to define the `__debugInfo()` magic method on enums.
187187
RFC: https://wiki.php.net/rfc/debugable-enums
188188

189+
- Curl:
190+
. curl_getinfo() return array now includes a new size_delivered key,
191+
which indicates the total number of bytes passed to the download
192+
write callback. This value can also be obtained by passing
193+
CURLINFO_SIZE_DELIVERED as the $option parameter.
194+
Requires libcurl 8.20.0 or later.
195+
189196
- Fileinfo:
190197
. finfo_file() now works with remote streams.
191198

@@ -399,6 +406,9 @@ PHP 8.6 UPGRADE NOTES
399406
10. New Global Constants
400407
========================================
401408

409+
- Curl:
410+
. CURLINFO_SIZE_DELIVERED (libcurl >= 8.20.0).
411+
402412
- Sockets:
403413
. TCP_USER_TIMEOUT (Linux only).
404414
. AF_UNSPEC.

ext/curl/curl.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,6 +3117,13 @@
31173117
*/
31183118
const CURLINFO_CONN_ID = UNKNOWN;
31193119
#endif
3120+
#if LIBCURL_VERSION_NUM >= 0x081400 /* Available since 8.20.0 */
3121+
/**
3122+
* @var int
3123+
* @cvalue CURLINFO_SIZE_DELIVERED
3124+
*/
3125+
const CURLINFO_SIZE_DELIVERED = UNKNOWN;
3126+
#endif
31203127
/**
31213128
* @var int
31223129
* @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
@@ -2456,6 +2456,11 @@ PHP_FUNCTION(curl_getinfo)
24562456
if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) {
24572457
CAAD("size_download", d_code);
24582458
}
2459+
#if LIBCURL_VERSION_NUM >= 0x081400 /* Available since 8.20.0 */
2460+
if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DELIVERED , &l_code) == CURLE_OK) {
2461+
CAAL("size_delivered", l_code);
2462+
}
2463+
#endif
24592464
if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) {
24602465
CAAD("speed_download", d_code);
24612466
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Curlinfo CURLINFO_SIZE_DELIVERED
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php
7+
$curl_version = curl_version();
8+
if ($curl_version['version_number'] < 0x081400) die("skip: test works only with curl >= 8.20.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");
19+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
20+
21+
$info = curl_getinfo($ch);
22+
var_dump(isset($info['size_delivered']));
23+
var_dump($info['size_delivered'] === 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['size_delivered']));
29+
var_dump(is_int($info['size_delivered']));
30+
var_dump(curl_getinfo($ch, CURLINFO_SIZE_DELIVERED) === $info['size_delivered']);
31+
var_dump(curl_getinfo($ch, CURLINFO_SIZE_DELIVERED) > 0);
32+
?>
33+
--EXPECT--
34+
bool(true)
35+
bool(true)
36+
bool(true)
37+
bool(true)
38+
bool(true)
39+
bool(true)
40+

0 commit comments

Comments
 (0)