-
Notifications
You must be signed in to change notification settings - Fork 7.9k
feat: enable persistent CurlShareHandle
objects
#15603
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
Changes from all commits
cdf66ab
4a19a98
e52ca6e
4de6a1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ | |
#include "ext/standard/url.h" | ||
#include "curl_private.h" | ||
|
||
ZEND_DECLARE_MODULE_GLOBALS(curl) | ||
|
||
#ifdef __GNUC__ | ||
/* don't complain about deprecated CURLOPT_* we're exposing to PHP; we | ||
need to keep using those to avoid breaking PHP API compatibility */ | ||
|
@@ -215,7 +217,11 @@ zend_module_entry curl_module_entry = { | |
NULL, | ||
PHP_MINFO(curl), | ||
PHP_CURL_VERSION, | ||
STANDARD_MODULE_PROPERTIES | ||
PHP_MODULE_GLOBALS(curl), | ||
PHP_GINIT(curl), | ||
PHP_GSHUTDOWN(curl), | ||
NULL, | ||
STANDARD_MODULE_PROPERTIES_EX | ||
}; | ||
/* }}} */ | ||
|
||
|
@@ -416,6 +422,17 @@ PHP_MINIT_FUNCTION(curl) | |
} | ||
/* }}} */ | ||
|
||
PHP_GINIT_FUNCTION(curl) | ||
{ | ||
zend_hash_init(&curl_globals->persistent_share_handles, 0, NULL, curl_share_free_persistent, true); | ||
GC_MAKE_PERSISTENT_LOCAL(&curl_globals->persistent_share_handles); | ||
} | ||
|
||
PHP_GSHUTDOWN_FUNCTION(curl) | ||
{ | ||
zend_hash_destroy(&curl_globals->persistent_share_handles); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if it would make sense to explicitly close persistent shares with |
||
} | ||
|
||
/* CurlHandle class */ | ||
|
||
static zend_object *curl_create_object(zend_class_entry *class_type) { | ||
|
@@ -728,8 +745,8 @@ static int curl_prereqfunction(void *clientp, char *conn_primary_ip, char *conn_ | |
// gets called. Return CURL_PREREQFUNC_OK immediately in this case to avoid | ||
// zend_call_known_fcc() with an uninitialized FCC. | ||
if (!ZEND_FCC_INITIALIZED(ch->handlers.prereq)) { | ||
return rval; | ||
} | ||
return rval; | ||
} | ||
|
||
#if PHP_CURL_DEBUG | ||
fprintf(stderr, "curl_prereqfunction() called\n"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--TEST-- | ||
Basic curl_share test | ||
--EXTENSIONS-- | ||
curl | ||
--SKIPIF-- | ||
<?php | ||
include 'skipif-nocaddy.inc'; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
function get_persistent_share_handle(): CurlShareHandle { | ||
return curl_share_init( | ||
[ | ||
CURL_LOCK_DATA_CONNECT, | ||
], | ||
"persistent-test", | ||
); | ||
} | ||
|
||
$sh1 = get_persistent_share_handle(); | ||
$ch1 = curl_init("https://localhost"); | ||
|
||
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch1, CURLOPT_SHARE, $sh1); | ||
|
||
$sh2 = get_persistent_share_handle(); | ||
$ch2 = curl_init("https://localhost"); | ||
|
||
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch2, CURLOPT_SHARE, $sh2); | ||
|
||
var_dump(curl_exec($ch1)); | ||
var_dump(curl_exec($ch2)); | ||
|
||
var_dump("second connect_time: " . (curl_getinfo($ch2)["connect_time"])); | ||
|
||
?> | ||
--EXPECT-- | ||
string(23) "Caddy is up and running" | ||
string(23) "Caddy is up and running" | ||
string(22) "second connect_time: 0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will need some discussion in the RFC whether we want to stop using the
EG(persistent_list)
.