<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
handle.php Run and record the run to the first few steps
<?phpsession_start (); $_session[' step '] = "; $n = 1;while ($n <=10) { $_session[' step '] = $n; Sleep (1); $n + +;} $_session[' Step ' = ' complete ';?>
getstep.php get run to the first few steps
<?phpsession_start (); Echo isset ($_session[' step ')? $_session[' Step ']: ';?>
the runtime finds that not every step is returned, but instead waits 10 seconds to return to complete immediately.
When you run session_start () , the session is locked. Until the page finishes running.
So the page runs in the meantime. Writing to the sesssion is only stored in memory. does not write to the session file.
While reading the session, you need to wait. Until the session lock unlocks the ability to read.
We can use session_write_close () to write data to the session file and end the session process. This will not have to wait for the page to finish running, but also to get to where to run.
But there's a problem with that. Is after the Sesssion_write_close () is finished running. No matter what the write operation of the session does not work. Because the session process has ended.
Therefore, the session needs to be written again. Add Session_Start () in front
session_start -start New or resume existing session
Session_write_close -write session data and end session
handle.php The following changes, you can get to which step to run
<?phpsession_start (); $_session[' step '] = "; $n = 1;while ($n <=10) { $_session[' step '] = $n; Session_write_close (); Writes the data to the session file and ends the session process session_start (); Create session process again sleep (1); $n + +;} $_session[' Step ' = ' complete ';? >
PHP session read/write lock