Yii Framework Forum: Quick Question: Dynamically Set Chttpsession's Timout - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Quick Question: Dynamically Set Chttpsession's Timout Rate Topic: -----

#1 User is offline   bschooly 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 13-November 13

Posted 25 November 2013 - 03:46 PM

I'm using in main.php:

                'session' => array(
                    'class' => 'CDbHttpSession',
                    'timeout' => 180,
                ),




But I want to set the timeout programatically. In my UserIdentity class after successful login I use:

Yii::app()->getSession()->setTimeout(30); 



But this seems to do nothing. How do I set the timeout?
0

#2 User is offline   bschooly 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 13-November 13

Posted 25 November 2013 - 06:24 PM

View Postbschooly, on 25 November 2013 - 03:46 PM, said:

I'm using in main.php:

                'session' => array(
                    'class' => 'CDbHttpSession',
                    'timeout' => 180,
                ),




But I want to set the timeout programatically. In my UserIdentity class after successful login I use:

Yii::app()->getSession()->setTimeout(30); 



But this seems to do nothing. How do I set the timeout?


Not sure but I think the CDbHttpSession class doesn't support this as it doesn't override the setTimeout() method (to make a db call). This lead me to try deferring the session open, creating the CDbHttpSession object myself, setting the timeout, then opening (starting) the session (I assume the open would use the configured/set timeout).

This didn't work either. It seems the session was already started. This is true even though I set autoStart to false. Are there circumstances where Yii starts the session for you even when autoStart = false?

Anybody know what is going on here?
0

#3 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,481
  • Joined: 04-March 10
  • Location:UK

Posted 26 November 2013 - 05:33 AM

I would assume that when you call getSession(), you're forcing Yii to create the session if it doesn't already exist so that it can return the session object to you.

EDIT:
Looking at the code, this seems to be incorrect.

What logic are you using to determine the timeout length?

EDIT 2:
What's the output if you write
    Yii::app()->session->setTimeout(30);
    echo Yii::app()->session->getTimeout();


I feel like your code should work as long as the session hasn't been started and the ini values are being correctly updated.
0

#4 User is offline   bschooly 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 13-November 13

Posted 26 November 2013 - 10:23 AM

View PostKeith, on 26 November 2013 - 05:33 AM, said:

I would assume that when you call getSession(), you're forcing Yii to create the session if it doesn't already exist so that it can return the session object to you.

EDIT:
Looking at the code, this seems to be incorrect.

What logic are you using to determine the timeout length?

EDIT 2:
What's the output if you write
    Yii::app()->session->setTimeout(30);
    echo Yii::app()->session->getTimeout();


I feel like your code should work as long as the session hasn't been started and the ini values are being correctly updated.



The answer is 30. But I think the issue is not that the object's setting is not being changed. Rather, I think the setting is not used post session start. The values must be set prior to the session being opened. At least that is my belief. The documentation for CHttpSession even says "Note, these properties must be set before the session is started." where properties includes settings like timeout.

That is why I was trying to defer the session start, so I could make the setting before the open. Unfortunately I think a session is created and started early on regardless of autoStart (I guess for the the guest user) and thus the opportunity to change this is lost.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users