session - php session_write_close() not commit until script execute complete? -
i test script in chrome.
<?php session_start(); if(isset($_session['ddd']) && $_session['ddd']) { exit("session set"); } else { $_session['ddd'] = true; session_write_close(); //session_commit() not work sleep(5); exit("session working"); }
i open php file in chrome, , echoes "session working" after 5 seconds.
if open file in new tab before 5 seconds have elapsed, echoes "session working", instead of "session set".
to confirm, if open file in new tab after 5 seconds have elapsed, echo "session set".
why? session_write_close
not commit session data immediately? if so, should want commit session immediately, how might do?
i sorry maybe have found reason! 1、it reason sleep function! if using sleep,the script file blocked. when new request php file excute after 5 seconds later.if use php file same code better. 2、someone said new session not fast enough.just @ link,the third tip! enter link description here now,i should create session first. ok,i create 3 php files.
fisrt - index.php set session;
<?php session_start(); $_session['ddd']=1; session_commit(); ?>
second -index2.php
<?php session_start(); if(isset($_session['ddd']) && $_session['ddd']==2) { echo("session set"); } else { $_session['ddd'] = 2; session_commit(); echo "session working"; sleep(5); } ?>
third index3.php
<?php session_start(); if(isset($_session['ddd']) && $_session['ddd']==2) { echo("session set"); } else { $_session['ddd'] = 2; session_commit(); echo "session working"; ($i=0;$i<10000000;$i++) { if(file_exists('sdsd')); } } ?>
it interesting.
fisrt lab: open index.php first. open index2.php in 2 tabs,you see, second tab of index2.php echo 'session set' but,it return after 5 seconds,yeah,sleep function block it,but session has written.good news.
second lab: open index.php first. open index2.php,index3.php in 2 tabs,you see, second tab echo 'session set' fast!
someone else if interesting can give me more help!
Comments
Post a Comment