Skip to content

Commit edc432b

Browse files
committed
ext/curl: Deprecate CURLOPT_DNS_USE_GLOBAL_CACHE constant
Libcurl `CURLOPT_DNS_USE_GLOBAL_CACHE` constant is no longer supported since libcurl[^1] 7.62. This feature is also not thread-safe, and we have special handling to emit warnings if it's used in ZTS builds. Impact: Close to 1,100 hits on GitHub code search[^2] [^1]: [CURLOPT_DNS_USE_GLOBAL_CACHE](https://curl.se/libcurl/c/CURLOPT_DNS_USE_GLOBAL_CACHE.html) [^2]: [GitHub code search: `CURLOPT_DNS_USE_GLOBAL_CACHE`](https://github.com/search?q=CURLOPT_DNS_USE_GLOBAL_CACHE+language%3APHP+++NOT+is%3Aarchived+NOT+path%3A%2F%5Eext%5C%2F%2F&type=code)
1 parent 5270ada commit edc432b

File tree

6 files changed

+13
-18
lines changed

6 files changed

+13
-18
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ PHP NEWS
133133
. Deprecated the CURLOPT_BINARYTRANSFER constant. (divinity76)
134134
. Bumped required libcurl version to 7.61.0. (Ayesh)
135135
. Added feature_list key to the curl_version() return value. (Ayesh)
136+
. Deprecated the CURLOPT_DNS_USE_GLOBAL_CACHE constant. (Ayesh Karunaratne)
136137

137138
- Date:
138139
. Added DateTime[Immutable]::createFromTimestamp. (Marc Bennewitz)

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ PHP 8.4 UPGRADE NOTES
393393

394394
- Curl:
395395
. The CURLOPT_BINARYTRANSFER constant is deprecated.
396+
. The CURLOPT_DNS_USE_GLOBAL_CACHE constant is deprecated. This feature
397+
is not thread-safe, and is no longer supported since libcurl 7.62.
396398

397399
- Date:
398400
. Calling DatePeriod::__construct(string $isostr, int $options = 0) is

ext/curl/curl.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
const CURLOPT_DNS_CACHE_TIMEOUT = UNKNOWN;
7575
/**
7676
* @var int
77-
* @cvalue CURLOPT_DNS_USE_GLOBAL_CACHE
77+
* @deprecated has no effect since Curl 7.62.0
7878
*/
79-
const CURLOPT_DNS_USE_GLOBAL_CACHE = UNKNOWN;
79+
const CURLOPT_DNS_USE_GLOBAL_CACHE = -1;
8080
/**
8181
* @var int
8282
* @cvalue CURLOPT_EGDSOCKET

ext/curl/curl_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/curl/interface.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,9 +1103,6 @@ static void _php_curl_set_default_options(php_curl *ch)
11031103
curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
11041104
curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header);
11051105
curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
1106-
#ifndef ZTS
1107-
curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
1108-
#endif
11091106
curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
11101107
curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */
11111108

@@ -1589,7 +1586,6 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
15891586
case CURLOPT_COOKIESESSION:
15901587
case CURLOPT_CRLF:
15911588
case CURLOPT_DNS_CACHE_TIMEOUT:
1592-
case CURLOPT_DNS_USE_GLOBAL_CACHE:
15931589
case CURLOPT_FAILONERROR:
15941590
case CURLOPT_FILETIME:
15951591
case CURLOPT_FORBID_REUSE:
@@ -1735,12 +1731,6 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
17351731
php_error_docref(NULL, E_WARNING, "CURLPROTO_FILE cannot be activated when an open_basedir is set");
17361732
return FAILURE;
17371733
}
1738-
# if defined(ZTS)
1739-
if (option == CURLOPT_DNS_USE_GLOBAL_CACHE && lval) {
1740-
php_error_docref(NULL, E_WARNING, "CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled");
1741-
return FAILURE;
1742-
}
1743-
# endif
17441734
error = curl_easy_setopt(ch->cp, option, lval);
17451735
break;
17461736
case CURLOPT_SAFE_UPLOAD:
@@ -2075,6 +2065,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
20752065
}
20762066

20772067
case CURLOPT_BINARYTRANSFER:
2068+
case CURLOPT_DNS_USE_GLOBAL_CACHE:
20782069
/* Do nothing, just backward compatibility */
20792070
break;
20802071

ext/curl/tests/bug71144.phpt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
--TEST--
22
Bug #71144 (Sementation fault when using cURL with ZTS)
3+
Since Curl 7.62, CURLOPT_DNS_USE_GLOBAL_CACHE has no effect, and
4+
using the CURLOPT_DNS_USE_GLOBAL_CACHE constant is deprecated
5+
in PHP 8.4.
36
--EXTENSIONS--
47
curl
5-
--SKIPIF--
6-
<?php if (!PHP_ZTS) { print "skip only for zts build"; } ?>
78
--FILE--
89
<?php
910
$ch = curl_init();
1011
var_dump(curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, 1));
1112
?>
1213
--EXPECTF--
13-
Warning: curl_setopt(): CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled in %sbug71144.php on line %d
14-
bool(false)
14+
Deprecated: Constant CURLOPT_DNS_USE_GLOBAL_CACHE is deprecated in %sbug71144.php on line %d
15+
bool(true)

0 commit comments

Comments
 (0)