Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Race hazard within a session?
11-01-2013, 04:46 PM #1
- Join Date
- Jun 2010
- Thanked 8 Times in 8 Posts
Race hazard within a session?
Is it possible for a race hazard to exist within (i.e. not between) a session? Or does
session_start();block all subsequent calls until the script has finished?
... sendAjaxRequest('myscript.php?x=flip'); sendAjaxRequest('myscript.php?x=flop'); ...
Now, suppose myscript.php looks like this:
for ($i=0; $i<100; $i++)
$_SESSION[$i] = myComplicatedFunction($_REQUEST[x]); // *** BANG!!! ***
Last edited by XmisterIS; 11-01-2013 at 04:49 PM.
11-01-2013, 08:32 PM #2
- Join Date
- Feb 2011
- Your Monitor
- Thanked 503 Times in 490 Posts
Sessions are thread safe. If you call a page while another request is doing it, the second request will not complete until the first one has finished. When the first finishes, the second requests call to session_start will continue.
It's easy to test, create a script on your localhost, set the time limit to a couple of minutes, print something to the browser and then sleep it for a minute. Open one tab / browser to call it and then open another to that same url and you'll see that nothing happens in the second browser / tab (sharing the same session) until the first one has completed.My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!
Users who have thanked tangoforce for this post: