I have a session handler class that calls session_write_close() at the end of the script. This insures that even if a header() or exit() is issued the session data is saved.
public function __destruct()
{
session_write_close();
}
However, I have noticed that for one of my AJAX pages TWO session updates are committed by the database layer.
My guess is that the [1] page loads and sends an [2] AJAX request. That [2] AJAX request must start the session before the [1] page has a chance to call session_write_close()
.
After the [2] AJAX page has loaded the session then the [1] page finally saves the session and then shortly after the [2] AJAX request saves it's session - which overwrites the first one!
It might look like this:
[1] page loads session
[1] page sends output
[2] ajax loads session
[1] page saves session
[2] ajax sends output
[2] ajax saves session
What do I do to make sure one page isn't loading a session before another has a chance to save the session?