Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
AJAX Session Rotation
  • Hi

    I am experiencing a really strange problem and I can't get to the bottom of it so hopefully someone can point me in the right direction.

    We run an eCommerce website with Fuel PHP. We use Fuel's Session and have a basket table that stores what the user currently has in their baskets. We have the session timeout of 7 days so the user can come back a few days later and still have their basket. 

    We have several ajax requests on the basket page to update the basket, change quantity or add additional items etc.

    The problem is that these ajax requests cause fuel to delete the session if the session is over 5 minutes old and remove the record from the session table.

    For the life of me I can't see a) the code that clears the session out and b) why that is getting called on ajax requests only. It feels like 5 minutes is some default value or setting but I can't see anything. These are our session settings which works fine and I assume REST requests use these settings are I can't see any session related time outs in the rest config file. Could it be loading core settings on ajax requests?

    // session expiration time, <= 0 means 2 years! (optional, default = 2 hours)
    'expiration_time' => 604800,

    // session ID rotation time  (optional, default = 300)
    'rotation_time' => false,

    After a lot of debugging and tracing the flow of execution I've tracked down the point at which it clears the session to this line 444 in the "fuel/core/classes/request.php

    $response = $action->invokeArgs($this->controller_instance, $this->method_params);

    If I exit() before this line the session doesn't clear so I'm fairly certain something in calling the actual controller method is causing it but the code that it runs in that function is really basic.

    public function action_someaction()
    {
    if (Model_somemodel::set_somevalue(1))
    {
    $this->response(array('valid' => true, "checked" => true), 200);
    }
    else
    {
    $this->response(array('valid' => false, 'error' => 'Error on update', 'basket_id' => $basket_id ), 200);
    }
    }

    Does anyone have any ideas. I've spent hours and hours on this and I'm sure I'm missing something really basic or there is a bug knocking around. Any help would be very much appreciated!

    Cheers
  • Thank you for the quick reply although I don't think so. We use the db session driver so everything is in the database so we shouldn't be hitting lock file problems. Unless it's something around ajax ajax requests not using the config properly under certain conditions.
  • mmm ok... weird that it also happens on database sessions... I sometime notice this on my file based sessions...
  • All our apps use db sessions, and rely on ajax a lot, and I can't recall the last time we had an issue with this. Not with recent Fuel versions at least...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion