Skip to content

Commit

Permalink
Allow to override default pool connection idle time (60 sec)
Browse files Browse the repository at this point in the history
Change-Id: Iccd56d4e5d2ab5966c6e6561f65701e5cd1aba79
Reviewed-on: http://review.couchbase.org/84020
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information
avsej committed Oct 4, 2017
1 parent bdc1297 commit 54a0ded
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/couchbase.php
Expand Up @@ -44,6 +44,12 @@
* controls the form of the documents, returned by the server if they were in JSON format. When true, it will generate
* arrays of arrays, otherwise instances of stdClass.
*
* * `couchbase.pool.max_idle_time_sec` (long), default: `60`
*
* controls the maximum interval the underlying connection object could be idle, i.e. without any data/query
* operations. All connections which idle more than this interval will be closed automatically. Cleanup function
* executed after each request using RSHUTDOWN hook.
*
* @package Couchbase
*/
namespace Couchbase {
Expand Down
2 changes: 2 additions & 0 deletions couchbase.c
Expand Up @@ -183,6 +183,7 @@ STD_PHP_INI_ENTRY("couchbase.encoder.compression", "off", PHP_INI_ALL
STD_PHP_INI_ENTRY("couchbase.encoder.compression_threshold", "0", PHP_INI_ALL, OnUpdateLongGEZero, enc_cmpr_threshold, zend_couchbase_globals, couchbase_globals)
STD_PHP_INI_ENTRY("couchbase.encoder.compression_factor", "0.0", PHP_INI_ALL, OnUpdateReal, enc_cmpr_factor, zend_couchbase_globals, couchbase_globals)
STD_PHP_INI_ENTRY("couchbase.decoder.json_arrays", "0", PHP_INI_ALL, OnUpdateBool, dec_json_array, zend_couchbase_globals, couchbase_globals)
STD_PHP_INI_ENTRY("couchbase.pool.max_idle_time_sec", "60", PHP_INI_ALL, OnUpdateLongGEZero, pool_max_idle_time, zend_couchbase_globals, couchbase_globals)
PHP_INI_END()
// clang-format on

Expand Down Expand Up @@ -212,6 +213,7 @@ static void php_extname_init_globals(zend_couchbase_globals *couchbase_globals)
couchbase_globals->enc_cmpr_threshold = 0;
couchbase_globals->enc_cmpr_factor = 0.0;
couchbase_globals->dec_json_array = 0;
couchbase_globals->pool_max_idle_time = 60;
}

PHP_MINIT_FUNCTION(couchbase)
Expand Down
1 change: 1 addition & 0 deletions couchbase.h
Expand Up @@ -103,6 +103,7 @@ char *enc_cmpr;
int enc_format_i;
int enc_cmpr_i;
long enc_cmpr_threshold;
long pool_max_idle_time;
double enc_cmpr_factor;
zend_bool dec_json_array;
ZEND_END_MODULE_GLOBALS(couchbase)
Expand Down
3 changes: 1 addition & 2 deletions src/couchbase/pool.c
Expand Up @@ -415,8 +415,7 @@ static int pcbc_destroy_idle_connections(
return 0;
}
now = time(NULL);
// abandoned more than 60 seconds ago
if ((now - conn->idle_at) > 60) {
if ((now - conn->idle_at) > PCBCG(pool_max_idle_time)) {
pcbc_destroy_connection_resource(res);
}
}
Expand Down

0 comments on commit 54a0ded

Please sign in to comment.