Skip to content

fix expiration #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix expiration
  • Loading branch information
crhg committed Feb 8, 2016
commit 27a22f3c0ab62f98d4e01e43caf2ad80840043fd
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