Yii Httpsession Timeout Not Working

same as title, in my config:

'session' => array(


   'timeout'=> 1200,



in my code:

$ssKey = 'MY_SS_KEY';

if (isset(Yii::app()->session[$ssKey])) {


} else {


   Yii::app()->session[$ssKey] = 'ok';


first time, it call function jobWithNotSession(), but after over 1200s (20 minute), it still call function jobWithNotSession, what’s wrong? somebody can help me?

if you call again after more than 1200 - the session expired and there is no stored value… so it seems pretty normal you get jobWithNotSession again…

First time, it call function jobWithNotSession and next time (time < 1200), it call function jobWithSession (working done!). But, after over 1200s (20 minute), it still call function jobWithSession, can u help me?

timeout expiration does not mean the session will be destroyed. It will be considered garbage on GC run, but GC is not fired on every request - by default there is only 1% chance it will be run (http://www.yiiframework.com/doc/api/1.1/CHttpSession#gCProbability-detail).

If you want to make sure session data won’t be available longer than ‘timeout’ you have to code it by yourself or mess with session cookie params:

or use CDbHttpSession which calls GC on every request (deleteing expired records is used to check if table exists in database)

I ran into a similar issue, you should check the PHP.ini settings as the defaults are used unless set in Yii. I think the defaults that I saw in my Php.ini would give a 0.1% chance of garbage collection. Their is a section in php.ini that talks about it.