Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ajax session concurency
  • I understood that using ajax and session could not always retrieve the correct updated variable.
    To avoid this, I intend to save my variable in the DB, and read each time I need (with the inconvenient to waste time and multiply calls), but I was wondering if there is a better option... What do you recommend ?

    Thank you for your advise
  • HarroHarro
    Accepted Answer
    Fuel is pretty resilient against this type of problems. I was responsible for fixing this issue in CodeIgniters session library back in 2010.

    The issue is that certain actions cause the session id to rotate. The rotation time in the session config is a parameter, but Auth for example will manually rotate every time there is an elevation of rights (for example a login).

    If you have multiple concurrent ajax calls, which have to be asynchronous, and two of them in parallel rotate the session id, then one will overwrite the other, since both requests share the same cookie.

    The Fuel session class can deal with a single overwrite, it can't deal with a double overwrite. You can minimize the problem by making sure your session id rotation time is not to short, I usually pick the time of the longest running ajax request. By default it's 300 seconds, if you have a single ajax call that runs 5 minutes, I think you have a design issue. ;-)

    To be honest, I still have to encounter the first issue related to this in the wild, I have only been able to reproduce it during test conditions, with 20 browser windows open on the same controller constantly fireing ajax requests with random delays.

    So I don't think there is too much of a problem, not enough to seriously worry about.
  • Thank you very much for your prompt answer.
    Actually my issue was not related to that but I setted a session var in a before function of one of my controller so even if I setted it via an ajax call, the session var value was not that was expected.
    So sorry to waist your time fuel rocks :)

Howdy, Stranger!

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

In this Discussion