PHP call Session_Start After the page is always loaded problem study _php tutorial

Source: Internet
Author: User
This article to introduce a PHP call Session_Start after the page is always loaded problem research, there is a need for friends to refer to. A PHP page execution time is relatively long (about 15 seconds), and as long as the page is not completed, the other page access is a long time loading state, only the page execution is complete, the remaining pages to open. What is this situation, after viewing, two pages are designed to the session operation, the sample code is as follows: Page One: Page two: Visit the page at the same time to access page two, you will find that page two will remain loaded until the page is completed. What is the cause of the problem? The answer is that PHP session mechanism in the mischief, PHP will only after the page code execution is completed before the session data will be written to the file, the page does not complete, the corresponding session file has been kept locked state, While the other pages to access the session file can only remain waiting state, which is why the page two need to wait until the page is completed before execution. Knowing why, how should we solve this problem? The answer is simple, and PHP already provides interfaces in the kernel: functions Session_write_close
The official document of the function is described as follows: Session data is usually stored after your script terminated without the need-call session_write_close (), BU T as session data is locked to prevent concurrent writes only one script could operate on a session at any time. When using framesets together with sessions you'll experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables AR E done. Session data is usually saved automatically at the end of your script without the need to call the Session_write_close function. But session to avoid data being written at the same time, lock the file to ensure that only one script can access the file at a time. When you use the frame page to access the session at the same time, you will encounter the file lock because of the framework of the continuous loading situation. You can use this function to reduce the load time of multiple frames as soon as you have finished processing the session variables. As in the previous question, we can call the Session_write_close function immediately after the session data is finished to write to the session data, so that it does not affect the normal operation of other pages. The code is as follows:

http://www.bkjia.com/PHPjc/632085.html www.bkjia.com true http://www.bkjia.com/PHPjc/632085.html techarticle This article to introduce a PHP call Session_Start after the page is always loaded problem research, there is a need for friends to refer to. A PHP page execution time is relatively long (about 15 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.