"PHP" session read/write lock

Source: Internet
Author: User

Event: Action $_session[' Start ' in a file = ' yes ';

Sleep (100); Sleep 100s

In this dormant time period, the B file Operation $_session[' start ' = ' no ';

Result: File B has been waiting until the end of a file hibernation is performed

Reason: Through Google search, learned that there is a read and write lock session

When the session_start () is executed, the operation of the session on the page is saved in memory until the end of the page execution is written in the session file. During this time, other documents will wait for the session operation;

The session will be locked. Until the completion of the page execution, the content from memory to write to the file;

Workaround: Manually write the data to the session file by calling Session_write_close () and end the session, and the other file does not have to wait to immediately operate the session. But the session is closed and needs to be called at a time

Session_Start () method, open session;

A file:

<?phpsession_start (); $_session[' start ']  = ' aaaa '; session_write_close ();//Writes data to the SESSION file, and end the session process sleep (); session_start (); Echo $_session[' Start '].microtime ();

B file: In the time period of the A file sleep, modify session value

<?phpsession_start (); $_session[' start ']  = ' bbbbb '; Session_write_close (); session_start (); Echo $_session[' Start '].microtime ();

  

  

"PHP" session read/write lock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.