php - ZF2: Why are my sessions logging out? -
my zf2 application logs out after short period of inactivity - say, 60 minutes or - , can't understand why.
i have 'auth' object singleton composes instance of zend\session\container
. constructor creates container following line:
$this->session = new container('auth');
the auth object has login()
method stores current user following line:
$this->getsession()->userid = $user->id;
the auth object has isloggedin()
method tests status follows:
if ($this->getsession()->userid) { return true; } return false;
that's pretty straightforward. yet, time time when bootstrap checking see if logged in, comes false. why?
here's printout of config session manager:
'cookie_domain' => '', 'cookie_httponly' => false, 'cookie_lifetime' => 604800, 'cookie_path' => '/', 'cookie_secure' => '', 'name' => 'myapplication', 'remember_me_seconds' => 1209600, 'save_path' => '/var/lib/php5', 'use_cookies' => true,
as can see, remember_me_seconds
, cookie_lifetime
set 2 weeks , 7 days respectively. there other setting should looking at?
i read somewhere default save handler, 'file', not support concurrency. bootstrap opens session container
auth namespace new container('auth')
. conflicting container in auth singleton ? doubt it, since problem occur in periods of high activity (not after period of inactivity). also, expect see exception.
woe me.
edit: worth noting session id not change when logged out, or upon logging in.
there many points why session can become invalid.
check following points:
- session cookie lifetime (should become invalid when closing browser)
- session lifetime itself
- cache_expire key in zf2 (should higher session lifetime)
try add this
//new section 'cache_expire' => 60 * 26, <-- may 'gc_maxlifetime' => 60 * 60 * 24, <-- or