Session destroyed after I site update

I created automatic site release system. My web root is actually symbolic link to the exact release dir.

This allows to make new version release an atomic procedure (with mv -Tf webroot_new webroot) without any 404 or 500 error messages.

Everything is fine except user is forced to log out after the site is switched to the new release (even if the new release has only minor view fixes).

I don’t use “allowAutoLogin” (all used data are stored in sessions) and sessions in turn are stored in the MySQL db.

My session params are:




'session'=>array(

  'sessionName'=>'SID',

  cookieMode'=>'only',

  'class'=>'system.web.CDbHttpSession',

  'connectionID'=>'db',

  'timeout'=>604800, // 7 weeks

  'cookieParams' => array(

    'lifetime' => 604800, // 7 weeks

  ),

  'sessionTableName'=>'session'

)



So basically nothing is stored under webroot (the only thing that is changed) which could affect sessions and cookies.

I don’t even know where to start digging. Please advice.

ok. user state in session is marked with application ID, so if the ID changes application cannot see user data and result is that you must re-login.

by default state key prefix is generated:




public function getStateKeyPrefix()

{

    if($this->_keyPrefix!==null)

        return $this->_keyPrefix;

    else

        return $this->_keyPrefix=md5('Yii.'.get_class($this).'.'.Yii::app()->getId());

}



and in CApplication:




public function getId()

{

    if($this->_id!==null)

        return $this->_id;

    else

        return $this->_id=sprintf('%x',crc32($this->getBasePath().$this->name));

}



where basePath is the root directory of the application. Defaults to ‘protected’.

now - if the basePath changes as in your case - application id is different.

there are two solutions: either set static stateKeyPrefix in your ‘user’ component, or set static ‘id’ in application (both in main.php config file):




return array(

  'id'=>'some-application-id',

  ...

  'components'=>array(

    ...

    'user'=>array(

      ...

      'keyStatePrefix'=>'my-key-state-prefix',

      ...



Great answer! My problem is solved. Redguy, thank you very much!