First look at an example, function:
1. Click on a button in the page, Ajax execution php,php with the session record to which step.
2. Use Ajax to poll another PHP, get the data in session, and where to go.
Session.html invokes PHP execution and outputs the execution to the first few steps
<!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
handle.php execute and record the execution to the first few steps
<?php
session_start ();
$_session[' Step '] = ';
$n = 1;
while ($n <=10) {
$_session[' step '] = $n;
Sleep (1);
$n + +;
}
$_session[' Step ' = ' complete ';
? >
getstep.php get execution to the first few steps
<?php
session_start ();
echo isset ($_session[' step ')? $_session[' Step ']: ';
? >
When executed, not every step is returned, but wait 10 seconds to return directly to complete.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/
When the session_start () is executed, the session is locked. Until the page execution completes.
So in the course of the page execution, writes to the sesssion are saved only in memory and are not written to the session file.
When you read the session, you need to wait until the session lock is unlocked before you can read it.
We can use Session_write_close () to write data to the session file and end the sessions process. This does not require you to wait for the page to complete, or to get to the next step of execution.
The problem, however, is that any write to the session does not work after Sesssion_write_close () has been executed. Because the session process has ended.
So when you need to write the session again, precede the session_start ()
Session_start-start New or resume existing session
Session_write_close-write session data and end session
Handle.php The following modifications, you can get to the step of execution
<?php
session_start ();
$_session[' Step '] = ';
$n = 1;
while ($n <=10) {
$_session[' step '] = $n;
Session_write_close (); Writes the data to the session file and ends the sessions process
session_start (); Recreate session process sleep
(1);
$n + +;
}
$_session[' Step ' = ' complete ';
? >