Richard_Grant Posted September 16, 2014 Share Posted September 16, 2014 Can someone dumb the function session_write_close() to me? Ive read this http://php.net/manual/en/function.session-write-close.php and i still don't understand! Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted September 16, 2014 Solution Share Posted September 16, 2014 It writes out the session data to storage and then closes it. What exactly it does depends on the backend you are using for sessions. For the default file-based sessions what it does is write the contents of $_SESSION to the file, closes the file, and releases the lock. PHP will do this automatically at the end of the script, however there may be instances in which you want to do it earlier so the function is there for you to use if desired. 1 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 16, 2014 Share Posted September 16, 2014 This function is much more important than kicken seems to think. Since sessions get an exclusive lock when they're opened, that means all other processes have to wait until the lock is released again. They cannot run simultaneously. If you're using Ajax or a similar technique, that's a big problem, because it essentially breaks the asynchronicity: All requests are processed one after another, synchronized by the locking mechanism. To make this problem less bad, the session should be closed as early as possible. So you start the session, do what you need to do and then close it again with session_write_close(). This releases the lock and lets other processes access the session. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.