Skip to content

Commit 27a22f3

Browse files
committed
fix expiration
1 parent 938f6bc commit 27a22f3

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

php_memcached_session.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern ZEND_DECLARE_MODULE_GLOBALS(php_memcached)
2525
#define MEMC_SESS_DEFAULT_LOCK_WAIT 150000
2626
#define MEMC_SESS_LOCK_EXPIRATION 30
2727

28+
#define REALTIME_MAXDELTA 60*60*24*30
29+
2830
ps_module ps_mod_memcached = {
2931
PS_MOD_UPDATE_TIMESTAMP(memcached)
3032
};
@@ -92,16 +94,26 @@ int php_memc_session_minit(int module_number)
9294
return SUCCESS;
9395
}
9496

97+
static
98+
time_t s_adjust_expiration(zend_long expiration)
99+
{
100+
if (expiration <= REALTIME_MAXDELTA) {
101+
return expiration;
102+
} else {
103+
return time(NULL) + expiration;
104+
}
105+
}
106+
95107
static
96108
time_t s_lock_expiration()
97109
{
98110
if (MEMC_SESS_INI(lock_expiration) > 0) {
99-
return time(NULL) + MEMC_SESS_INI(lock_expiration);
111+
return s_adjust_expiration(MEMC_SESS_INI(lock_expiration));
100112
}
101113
else {
102114
zend_long max_execution_time = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
103115
if (max_execution_time > 0) {
104-
return time(NULL) + max_execution_time;
116+
return s_adjust_expiration(max_execution_time);
105117
}
106118
}
107119
return 0;
@@ -111,7 +123,7 @@ static
111123
time_t s_session_expiration(zend_long maxlifetime)
112124
{
113125
if (maxlifetime > 0) {
114-
return time(NULL) + maxlifetime;
126+
return s_adjust_expiration(maxlifetime);
115127
}
116128
return 0;
117129
}

0 commit comments

Comments
 (0)