PHP session Read and write lock problem

Source: Internet
Author: User
Tags session id php session php code

After the Session_Start (), the corresponding session file is locked until the current script is closed to unlock it.
During lockdown, Session_Start () begins when a process accesses a file that has the same session ID to be unlocked.
The solution is to call Session_write_close () to write the data to the file and end the session after it has been set.

For example, the following code

PHP Code
<?php
Session_name ("Stest");
session_id ("TestID");
Session_Start ();
$_session["Count"]=0;
Session_write_close ();
Sleep (10);
echo "Success";
?>


If you do not join Session_write_close ();
Concurrent 3 Processes access the page, the first process executes 10 seconds, the second executes 20 seconds, and the third executes for 30 seconds.
After joining Session_write_close ()
Concurrent 3 processes will be completed in 10 seconds



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.