views:

37

answers:

2

Hi.

Is there any way to disable the session locking in PHP while using the default session handler?

[EDIT:] Or is there at least a way to restart a session after calling session_write_close()? `session_start()' does not work if any output is already sent to the browser.

Thanks, Taloncor

A: 

Other than using session_write_close() ? None that I know of.

Mark Baker
+2  A: 

You don't want to disable it... If you do, you'll potentially run into all sorts of weird issues where you login on one window, be logged out on another and then wind up in an inconsistent state... The locking is there for a reason...

Instead, close the session very early if you know you are not going to write to it in that request. Once you start it, you'll be able to read from it for the whole request (unless you re-start it, or do some other special things) even after you call session_write_close. So what you would do, is check the request to see if it's a write request, and if it's not, just close it right after opening it. Note that this may have some adverse affects if you later try writing to the session (For Captcha or CSRF protection or something else), so use with caution...

But instead of trying to get around it, I would put my effort into either shortening the request lengths (to reduce lock contention), or making cookieless requests for those requests that don't need the session at all...

ircmaxell
No really an answer to the question, but very helpful in other ways. Thank you.I invoke long running from my scripts and missed the obvious solution to call session_write_close beforehand and session_start afterwards.
Taloncor
You need to call `session_write_close` AFTER `session_start`. Otherwise it's not going to do anything. I'm not sure if it's possible to re-start the session later, but you can try that...
ircmaxell
Doesn't work. Doh.Is there a way to restart a session?
Taloncor
What doesn't work? What do you mean restart a session? More details are needed...
ircmaxell