The execution time of a PHP page is relatively long (about 15 seconds). As long as the page has not been executed, other page accesses are in the loading status for a long time, and only the page has been executed, the remaining pages can be opened.
What is the situation? After checking, the two pages are designed for SESSION operations. The sample code is as follows:
Page 1:
Page 2:
When you access page 2 at the same time, you will find that page 2 remains loaded until the execution of page 1 is complete.
What is the cause of the problem?
The answer is that PHP's SESSION mechanism is at odds. PHP will write SESSION data to the file only after the page code is executed, and the page will not be executed, the corresponding SESSION files are always locked, while other pages have to wait for access to this SESSION file, this is why page 2 is executed only after Page 1 is executed.
After knowing the cause, how should we solve this problem?
The answer is simple. PHP already provides related interfaces in the kernel: functions.Session_write_close
The official function documentation is described as follows:
Session data is usually stored after your script terminated without the need to call session_write_close (), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. when using framesets together with sessions you will 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 are done.
Session data is automatically saved after your script ends without calling the session_write_close function. However, to prevent data from being written at the same time, the session locks the file to ensure that only one script can access the file at a time. When you access the SESSION on the Framework page at the same time, the framework will be continuously loaded due to file locking. You can use this function immediately after processing the SESSION variable to reduce the loading time of multiple frameworks.
As in the previous issue, we can directly call the session_write_close function to write SESSION data immediately after the session data is operated, so that the normal operation of other pages will not be affected. The code is as follows: