|
67 | 67 |
|
68 | 68 | #include "curl_arginfo.h" |
69 | 69 |
|
| 70 | +ZEND_DECLARE_MODULE_GLOBALS(curl) |
| 71 | + |
70 | 72 | #ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */ |
71 | 73 | static MUTEX_T *php_curl_openssl_tsl = NULL; |
72 | 74 |
|
@@ -215,18 +217,34 @@ zend_module_entry curl_module_entry = { |
215 | 217 | NULL, |
216 | 218 | PHP_MINFO(curl), |
217 | 219 | PHP_CURL_VERSION, |
218 | | - STANDARD_MODULE_PROPERTIES |
| 220 | + PHP_MODULE_GLOBALS(curl), |
| 221 | + PHP_GINIT(curl), |
| 222 | + PHP_GSHUTDOWN(curl), |
| 223 | + NULL, |
| 224 | + STANDARD_MODULE_PROPERTIES_EX |
219 | 225 | }; |
220 | 226 | /* }}} */ |
221 | 227 |
|
222 | 228 | #ifdef COMPILE_DL_CURL |
223 | 229 | ZEND_GET_MODULE (curl) |
224 | 230 | #endif |
225 | 231 |
|
| 232 | +PHP_GINIT_FUNCTION(curl) |
| 233 | +{ |
| 234 | + zend_hash_init(&curl_globals->persistent_curlsh, 0, NULL, curl_share_free_persistent_curlsh, true); |
| 235 | + GC_MAKE_PERSISTENT_LOCAL(&curl_globals->persistent_curlsh); |
| 236 | +} |
| 237 | + |
| 238 | +PHP_GSHUTDOWN_FUNCTION(curl) |
| 239 | +{ |
| 240 | + zend_hash_destroy(&curl_globals->persistent_curlsh); |
| 241 | +} |
| 242 | + |
226 | 243 | /* CurlHandle class */ |
227 | 244 |
|
228 | 245 | zend_class_entry *curl_ce; |
229 | 246 | zend_class_entry *curl_share_ce; |
| 247 | +zend_class_entry *curl_share_persistent_ce; |
230 | 248 | static zend_object_handlers curl_object_handlers; |
231 | 249 |
|
232 | 250 | static zend_object *curl_create_object(zend_class_entry *class_type); |
@@ -410,6 +428,10 @@ PHP_MINIT_FUNCTION(curl) |
410 | 428 |
|
411 | 429 | curl_share_ce = register_class_CurlShareHandle(); |
412 | 430 | curl_share_register_handlers(); |
| 431 | + |
| 432 | + curl_share_persistent_ce = register_class_CurlSharePersistentHandle(); |
| 433 | + curl_share_persistent_register_handlers(); |
| 434 | + |
413 | 435 | curlfile_register_class(); |
414 | 436 |
|
415 | 437 | return SUCCESS; |
@@ -2281,16 +2303,24 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue |
2281 | 2303 |
|
2282 | 2304 | case CURLOPT_SHARE: |
2283 | 2305 | { |
2284 | | - if (Z_TYPE_P(zvalue) == IS_OBJECT && Z_OBJCE_P(zvalue) == curl_share_ce) { |
2285 | | - php_curlsh *sh = Z_CURL_SHARE_P(zvalue); |
2286 | | - curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share); |
| 2306 | + if (Z_TYPE_P(zvalue) != IS_OBJECT) { |
| 2307 | + break; |
| 2308 | + } |
2287 | 2309 |
|
2288 | | - if (ch->share) { |
2289 | | - OBJ_RELEASE(&ch->share->std); |
2290 | | - } |
2291 | | - GC_ADDREF(&sh->std); |
2292 | | - ch->share = sh; |
| 2310 | + if (Z_OBJCE_P(zvalue) != curl_share_ce && Z_OBJCE_P(zvalue) != curl_share_persistent_ce) { |
| 2311 | + break; |
2293 | 2312 | } |
| 2313 | + |
| 2314 | + php_curlsh *sh = Z_CURL_SHARE_P(zvalue); |
| 2315 | + |
| 2316 | + curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share); |
| 2317 | + |
| 2318 | + if (ch->share) { |
| 2319 | + OBJ_RELEASE(&ch->share->std); |
| 2320 | + } |
| 2321 | + |
| 2322 | + GC_ADDREF(&sh->std); |
| 2323 | + ch->share = sh; |
2294 | 2324 | } |
2295 | 2325 | break; |
2296 | 2326 |
|
|
0 commit comments