PHP Classes

you can lock, unlock, lock and unlock again

Recommend this page to a friend!

      PHP Classes blog  >  Fix the AJAX Requests...  >  All threads  >  you can lock, unlock, lock and...  >  (Un) Subscribe thread alerts  
Subject:you can lock, unlock, lock and...
Summary:use session_start() and session_write_close() can be repeated
Messages:2
Author:Lee Eden
Date:2015-05-04 14:48:08
Update:2015-05-04 21:25:50
 

  1. you can lock, unlock, lock and...   Reply   Report abuse  
Picture of Lee Eden Lee Eden - 2015-05-04 19:47:25
It's also useful to know that you can use session_start() and session_write_close() multiple times within a script. So you can, for example, get values to use at the start of the script and then change them later without locking the session in between by doing something like:

session_start();
$loggedUser=$_SESSION['user'];
$orderID=$_SESSION['orderID'];
$orderStatus=$_SESSION['orderStatus'];
session_write_close();

sleep(5); // do a load of stuff

session_start();
$_SESSION['orderStatus']='calculated';
session_write_close();

  2. Re: you can lock, unlock, lock and...   Reply   Report abuse  
Picture of Eslam Mahmoud Eslam Mahmoud - 2015-05-04 21:25:50 - In reply to message 1 from Lee Eden
Perfect point i just added a new action to test this as an answer for another question about centralizing the call to session vars.

As i was saying the only thing need to be considered is the synchronization.

You can review the example over here https://github.com/eslam-mahmoud/PHP-session-locking-problem-with-Ajax