What if you need to write to session later....

Recommend this page to a friend!

      PHP Classes blog  >  Fix the AJAX Requests...  >  All threads  >  What if you need to write to session...  >  (Un) Subscribe thread alerts  
Subject:What if you need to write to session...
Summary:What if you don't know you are going to change the session...
Messages:2
Author:Nikolaos Giannopoulos
Date:2015-05-04 17:24:59
Update:2015-05-04 21:23:28
 

  1. What if you need to write to session...   Reply   Report abuse  
Picture of Nikolaos Giannopoulos Nikolaos Giannopoulos - 2015-05-04 19:48:14
We centralize session calls and would consider invoking this method all the time however if we needed to know beforehand that we were not going to write to the session and either start a session and not close the session file "vs." just start a session and close the session file it would introduce all sorts of complexity to our application.

So, what if you don't know you are going to change the session in the same script and need to at some point? Is there a way to re-open the session file just prior to making a change and then closing it again.

  2. Re: What if you need to write to session...   Reply   Report abuse  
Picture of Eslam Mahmoud Eslam Mahmoud - 2015-05-04 21:23:28 - In reply to message 1 from Nikolaos Giannopoulos
If your problem/concern is about data lose if you tried to close then open the session it will not lose any data

So if you centralized the call to session starting with open then close it will do no harm, just consider the synchronization between actions.

I added a new action button in the code you can check it to test your hypothesis.
check the code again on https://github.com/eslam-mahmoud/PHP-session-locking-problem-with-Ajax

 

For more information send a message to info at phpclasses dot org.