Jump to content

Session_Write_close()


Richard_Grant
Go to solution Solved by kicken,

Recommended Posts

  • Solution

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.

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.