Skip to content

Commit 54a0ded

Browse files
committed
Allow to override default pool connection idle time (60 sec)
Change-Id: Iccd56d4e5d2ab5966c6e6561f65701e5cd1aba79 Reviewed-on: http://review.couchbase.org/84020 Tested-by: Build Bot <[email protected]> Reviewed-by: Sergey Avseyev <[email protected]>
1 parent bdc1297 commit 54a0ded

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

api/couchbase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
* controls the form of the documents, returned by the server if they were in JSON format. When true, it will generate
4545
* arrays of arrays, otherwise instances of stdClass.
4646
*
47+
* * `couchbase.pool.max_idle_time_sec` (long), default: `60`
48+
*
49+
* controls the maximum interval the underlying connection object could be idle, i.e. without any data/query
50+
* operations. All connections which idle more than this interval will be closed automatically. Cleanup function
51+
* executed after each request using RSHUTDOWN hook.
52+
*
4753
* @package Couchbase
4854
*/
4955
namespace Couchbase {

couchbase.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ STD_PHP_INI_ENTRY("couchbase.encoder.compression", "off", PHP_INI_ALL
183183
STD_PHP_INI_ENTRY("couchbase.encoder.compression_threshold", "0", PHP_INI_ALL, OnUpdateLongGEZero, enc_cmpr_threshold, zend_couchbase_globals, couchbase_globals)
184184
STD_PHP_INI_ENTRY("couchbase.encoder.compression_factor", "0.0", PHP_INI_ALL, OnUpdateReal, enc_cmpr_factor, zend_couchbase_globals, couchbase_globals)
185185
STD_PHP_INI_ENTRY("couchbase.decoder.json_arrays", "0", PHP_INI_ALL, OnUpdateBool, dec_json_array, zend_couchbase_globals, couchbase_globals)
186+
STD_PHP_INI_ENTRY("couchbase.pool.max_idle_time_sec", "60", PHP_INI_ALL, OnUpdateLongGEZero, pool_max_idle_time, zend_couchbase_globals, couchbase_globals)
186187
PHP_INI_END()
187188
// clang-format on
188189

@@ -212,6 +213,7 @@ static void php_extname_init_globals(zend_couchbase_globals *couchbase_globals)
212213
couchbase_globals->enc_cmpr_threshold = 0;
213214
couchbase_globals->enc_cmpr_factor = 0.0;
214215
couchbase_globals->dec_json_array = 0;
216+
couchbase_globals->pool_max_idle_time = 60;
215217
}
216218

217219
PHP_MINIT_FUNCTION(couchbase)

couchbase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ char *enc_cmpr;
103103
int enc_format_i;
104104
int enc_cmpr_i;
105105
long enc_cmpr_threshold;
106+
long pool_max_idle_time;
106107
double enc_cmpr_factor;
107108
zend_bool dec_json_array;
108109
ZEND_END_MODULE_GLOBALS(couchbase)

src/couchbase/pool.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ static int pcbc_destroy_idle_connections(
415415
return 0;
416416
}
417417
now = time(NULL);
418-
// abandoned more than 60 seconds ago
419-
if ((now - conn->idle_at) > 60) {
418+
if ((now - conn->idle_at) > PCBCG(pool_max_idle_time)) {
420419
pcbc_destroy_connection_resource(res);
421420
}
422421
}

0 commit comments

Comments
 (0)