From 6930a7b64dc633c7b6d8417f5529a5a07fd6aafd Mon Sep 17 00:00:00 2001 From: Christophe Jaillet Date: Tue, 1 Sep 2015 08:23:01 +0000 Subject: [PATCH] Allow 0 as a valid value (never close idle connections) Increased maximum allowed value to 3600 s (1 hour) Use 'ap_timeout_parameter_parse' to allow more flexible configuration (i.e. h, min, s, ms suffixes) Use 'apr_time_from_sec' when applicable. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1700418 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/mod/mod_socache_memcache.xml | 30 +++++++++++++++++++----- modules/cache/mod_socache_memcache.c | 19 ++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/docs/manual/mod/mod_socache_memcache.xml b/docs/manual/mod/mod_socache_memcache.xml index c0f3422f27..94a64ad84e 100644 --- a/docs/manual/mod/mod_socache_memcache.xml +++ b/docs/manual/mod/mod_socache_memcache.xml @@ -55,20 +55,38 @@ MemcacheConnTTL Keepalive time for idle connections -MemcacheConnTTL seconds -MemcacheConnTTL 15 +MemcacheConnTTL num[units] +MemcacheConnTTL 15s server config virtual host +Available in Apache 2.4.17 and later -

Set the time, in seconds, to keep idle connections with the memcache - server(s) alive (threaded platforms only).

+

Set the time to keep idle connections with the memcache server(s) + alive (threaded platforms only).

-

Valid values for MemcacheConnTTL are integers - from 1 to 1800. That is to say, up to half an hour.

+

Valid values for MemcacheConnTTL are times + up to one hour. 0 means no timeout.

+ +

This timeout defaults to units of seconds, but accepts + suffixes for milliseconds (ms), seconds (s), minutes (min), and hours (h). +

+ +

Before Apache 2.4.17, this timeout was hardcoded and its value was 600 usec. + So, the closest configuration to match the legacy behaviour is to set + MemcacheConnTTL to 1ms.

+ + + +# Set a timeout of 10 minutes +MemcacheConnTTL 10min +# Set a timeout of 60 seconds +MemcacheConnTTL 60 + +
diff --git a/modules/cache/mod_socache_memcache.c b/modules/cache/mod_socache_memcache.c index 795e23b579..86577a9f7b 100644 --- a/modules/cache/mod_socache_memcache.c +++ b/modules/cache/mod_socache_memcache.c @@ -51,13 +51,13 @@ #endif #ifndef MC_DEFAULT_SERVER_TTL -#define MC_DEFAULT_SERVER_TTL (15*1000*1000) /* 15 seconds */ +#define MC_DEFAULT_SERVER_TTL apr_time_from_sec(15) #endif module AP_MODULE_DECLARE_DATA socache_memcache_module; typedef struct { - unsigned int ttl; + apr_uint32_t ttl; } socache_mc_svr_cfg; struct ap_socache_instance_t { @@ -331,19 +331,22 @@ static void *create_server_config(apr_pool_t *p, server_rec *s) static const char *socache_mc_set_ttl(cmd_parms *cmd, void *dummy, const char *arg) { + apr_interval_time_t ttl; socache_mc_svr_cfg *sconf = ap_get_module_config(cmd->server->module_config, &socache_memcache_module); - int i; - i = atoi(arg); + if (ap_timeout_parameter_parse(arg, &ttl, "s") != APR_SUCCESS) { + return apr_pstrcat(cmd->pool, cmd->cmd->name, + " has wrong format", NULL); + } - if ((i < 1) || (i > 1800)) { + if ((ttl < apr_time_from_sec(0)) || (ttl > apr_time_from_sec(3600))) { return apr_pstrcat(cmd->pool, cmd->cmd->name, - " must be a number between 1 and 1800.", NULL); + " can only be 0 or up to one hour.", NULL); } /* apr_memcache_server_create needs a ttl in usec. */ - sconf->ttl = i * 1000 * 1000; + sconf->ttl = ttl; return NULL; } @@ -359,7 +362,7 @@ static void register_hooks(apr_pool_t *p) static const command_rec socache_memcache_cmds[] = { AP_INIT_TAKE1("MemcacheConnTTL", socache_mc_set_ttl, NULL, RSRC_CONF, - "TTL used for the connection with the memcache server(s), in seconds"), + "TTL used for the connection with the memcache server(s)"), { NULL } }; -- 2.40.0