Skip to content

Commit

Permalink
Merge pull request #216 from crhg/fix_expiration
Browse files Browse the repository at this point in the history
fix expiration
  • Loading branch information
mkoppanen committed Feb 8, 2016
2 parents 938f6bc + 27a22f3 commit 4d44086
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions php_memcached_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extern ZEND_DECLARE_MODULE_GLOBALS(php_memcached)
#define MEMC_SESS_DEFAULT_LOCK_WAIT 150000
#define MEMC_SESS_LOCK_EXPIRATION 30

#define REALTIME_MAXDELTA 60*60*24*30

ps_module ps_mod_memcached = {
PS_MOD_UPDATE_TIMESTAMP(memcached)
};
Expand Down Expand Up @@ -92,16 +94,26 @@ int php_memc_session_minit(int module_number)
return SUCCESS;
}

static
time_t s_adjust_expiration(zend_long expiration)
{
if (expiration <= REALTIME_MAXDELTA) {
return expiration;
} else {
return time(NULL) + expiration;
}
}

static
time_t s_lock_expiration()
{
if (MEMC_SESS_INI(lock_expiration) > 0) {
return time(NULL) + MEMC_SESS_INI(lock_expiration);
return s_adjust_expiration(MEMC_SESS_INI(lock_expiration));
}
else {
zend_long max_execution_time = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
if (max_execution_time > 0) {
return time(NULL) + max_execution_time;
return s_adjust_expiration(max_execution_time);
}
}
return 0;
Expand All @@ -111,7 +123,7 @@ static
time_t s_session_expiration(zend_long maxlifetime)
{
if (maxlifetime > 0) {
return time(NULL) + maxlifetime;
return s_adjust_expiration(maxlifetime);
}
return 0;
}
Expand Down

0 comments on commit 4d44086

Please sign in to comment.