diff options
author | Pavlo Yatsukhnenko <yatsukhnenko@gmail.com> | 2019-02-16 20:48:02 +0300 |
---|---|---|
committer | michael-grunder <michael.grunder@gmail.com> | 2019-03-19 23:05:40 +0300 |
commit | b994ee42df8a4acf4b5cc16faeb09a60619e3245 (patch) | |
tree | 8c9eb4dce1deb56476499bdaf3a2075487de3802 /redis.c | |
parent | b2511d632cc2fb4a4c4cda07ae9403e37bf9055b (diff) |
Persistent connections pool
Diffstat (limited to 'redis.c')
-rw-r--r-- | redis.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -55,6 +55,8 @@ extern int le_cluster_slot_cache; extern zend_function_entry redis_array_functions[]; extern zend_function_entry redis_cluster_functions[]; +int le_redis_pconnect; + PHP_INI_BEGIN() /* redis arrays */ PHP_INI_ENTRY("redis.arrays.algorithm", "", PHP_INI_ALL, NULL) @@ -81,6 +83,9 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("redis.clusters.seeds", "", PHP_INI_ALL, NULL) PHP_INI_ENTRY("redis.clusters.timeout", "0", PHP_INI_ALL, NULL) + /* redis pconnect */ + PHP_INI_ENTRY("redis.pconnect.pooling_enabled", "0", PHP_INI_ALL, NULL) + /* redis session */ PHP_INI_ENTRY("redis.session.locking_enabled", "0", PHP_INI_ALL, NULL) PHP_INI_ENTRY("redis.session.lock_expire", "0", PHP_INI_ALL, NULL) @@ -711,6 +716,25 @@ static void add_class_constants(zend_class_entry *ce, int is_cluster TSRMLS_DC) zend_declare_class_constant_stringl(ce, "BEFORE", 6, "before", 6 TSRMLS_CC); } +static void +redis_pconnect_dtor(void *ptr TSRMLS_DC) +{ + php_stream_pclose(*(php_stream **)ptr); +} + +static ZEND_RSRC_DTOR_FUNC(redis_connections_pool_dtor) +{ +#if (PHP_MAJOR_VERSION < 7) + zend_resource *res = rsrc; +#endif + + if (res->ptr) { + zend_llist_apply(res->ptr, redis_pconnect_dtor TSRMLS_CC); + zend_llist_destroy(res->ptr); + pefree(res->ptr, 1); + } +} + /** * PHP_MINIT_FUNCTION */ @@ -781,6 +805,10 @@ PHP_MINIT_FUNCTION(redis) php_session_register_module(&ps_mod_redis_cluster); #endif + /* Register resource destructors */ + le_redis_pconnect = zend_register_list_destructors_ex(NULL, redis_connections_pool_dtor, + "phpredis persistent connections pool", module_number); + return SUCCESS; } |