Ajax calls are not keeping session alive

I’ve been searching the forums and google everywhere and can’t figure out why ajax calls are not keeping the session alive.

As a test I have a client side ajax call polling every 5 seconds using setInterval and I do get valid responses from the controller it sends requests to.

In /config/main.php using the following settings:


'session' => array(

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

            'connectionID' => 'db',

            'sessionTableName' => 'session',

            'autoCreateSessionTable' => true,

            'timeout' => 1200,

and


'user' => array(

            'allowAutoLogin' => true,

Also in CWebUser->login using the default $duration = 0

Where should I look next?

Hi missingdigit, welcome to the forum.

try autoStart property of the component:

http://www.yiiframework.com/doc/api/1.1/CHttpSession#autoStart-detail

Thank you for the suggestion. Previously I had tested adding a call to session_start() in my ajax handling controller method and it returned a php error saying that the session had already been started.

I did a global search across my project and $autoStart is not being changed by any of my code. I see that the default value is true, which seems to be confirmed by my session_start test.

Oh, my bad.

Your’re right. “autoStart” defaults to true.

Do not mess with session_start() because Yii is handling it automatically.

Have you added your AJAX action to ‘allow’ filters in your controller?