Skip to content

Commit b9af433

Browse files
committed
Add new curl_upkeep() function
1 parent cec20f6 commit b9af433

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PHP NEWS
1212

1313
- Curl:
1414
. Added new constants from cURL 7.62 to 7.80. (Pierrick)
15+
. New function curl_upkeep(). (Pierrick)
1516

1617
- MBString:
1718
. Backwards-compatible mappings for 0x5C/0x7E in Shift-JIS are restored,

UPGRADING

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ PHP 8.2 UPGRADE NOTES
7777
. Added CURLINFO_EFFECTIVE_METHOD option and returning the effective
7878
HTTP method in curl_getinfo() return value.
7979
. Exposed multiple new constants from libcurl 7.62 to 7.80.
80+
. Added new function curl_upkeep() to perform any connection upkeep checks.
8081

8182
- OCI8:
8283
. Added an oci8.prefetch_lob_size directive and oci_set_prefetch_lob()
@@ -174,6 +175,9 @@ PHP 8.2 UPGRADE NOTES
174175
6. New Functions
175176
========================================
176177

178+
- Curl:
179+
. curl_upkeep() (libcurl >= 7.62.0)
180+
177181
- Reflection:
178182
. ReflectionFunction::isAnonymous()
179183
. ReflectionMethod::hasPrototype()

ext/curl/curl.stub.php

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ function curl_getinfo(CurlHandle $handle, ?int $option = null): mixed {}
5454
/** @refcount 1 */
5555
function curl_init(?string $url = null): CurlHandle|false {}
5656

57+
#if LIBCURL_VERSION_NUM >= 0x073E00 /* Available since 7.62.0 */
58+
function curl_upkeep(CurlHandle $handle): bool {}
59+
#endif
60+
5761
function curl_multi_add_handle(CurlMultiHandle $multi_handle, CurlHandle $handle): int {}
5862

5963
function curl_multi_close(CurlMultiHandle $multi_handle): void {}

ext/curl/curl_arginfo.h

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/curl/interface.c

+22
Original file line numberDiff line numberDiff line change
@@ -3989,3 +3989,25 @@ PHP_FUNCTION(curl_pause)
39893989
RETURN_LONG(curl_easy_pause(ch->cp, bitmask));
39903990
}
39913991
/* }}} */
3992+
3993+
#if LIBCURL_VERSION_NUM >= 0x073E00 /* Available since 7.62.0 */
3994+
/* {{{ perform connection upkeep checks */
3995+
PHP_FUNCTION(curl_upkeep)
3996+
{
3997+
CURLcode error;
3998+
zval *zid;
3999+
php_curl *ch;
4000+
4001+
ZEND_PARSE_PARAMETERS_START(1, 1)
4002+
Z_PARAM_OBJECT_OF_CLASS(zid, curl_ce)
4003+
ZEND_PARSE_PARAMETERS_END();
4004+
4005+
ch = Z_CURL_P(zid);
4006+
4007+
error = curl_easy_upkeep(ch->cp);
4008+
SAVE_CURL_ERROR(ch, error);
4009+
4010+
RETURN_BOOL(error == CURLE_OK);
4011+
}
4012+
/*}}} */
4013+
#endif

ext/curl/tests/curl_upkeep_001.phpt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
curl_upkeep() function
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php
7+
if (curl_version()['version_number'] < 0x073e00) die('skip requires curl >= 7.62.0');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
$url = "https://example.com";
13+
14+
$ch = curl_init();
15+
curl_setopt($ch,CURLOPT_URL,$url);
16+
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
17+
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0);
18+
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
19+
curl_setopt($ch, CURLOPT_UPKEEP_INTERVAL_MS, 200);
20+
if (curl_exec($ch)) {
21+
usleep(300);
22+
var_dump(curl_upkeep($ch));
23+
}
24+
curl_close($ch);
25+
?>
26+
--EXPECT--
27+
bool(true)

0 commit comments

Comments
 (0)