Initially, I just want to verify that session_start is blocking in the session. So, I am creating a PHP file as shown below. In principle, if the page view is flat, the page sleeps for 10 seconds; if the page view is odd, itโs not. And session_start is used to get the pageview in $ _ SESSION .
I tried to open the page in two tabs of the same browser. Unsurprisingly, the first tab takes 10 seconds, since I explicitly let her sleep. The second tab will not sleep, but it should be blocked by sessiont_start . This works as expected.
To my surprise, the output of the second page shows that session_start is running out of time. In fact, the entire page does not seem to take time to load. But in the browser, the page takes 10 seconds.
obtained lock Cost time: 0.00016689300537109 Start 1269739162.1997 End 1269739162.1998 allover time elpased : 0.00032305717468262 The page views: 101
Does PHP output session_start from a PHP page and execute it before other PHP instructions?
This is the code.
<?php function float_time() { list($usec, $sec) = explode(' ', microtime()); return (float)$sec + (float)$usec; } $allover_start_time = float_time(); $start_time = float_time(); session_start(); echo "obtained lock<br/>"; $end_time = float_time(); $elapsed_time = $end_time - $start_time; echo "Cost time: $elapsed_time <br>"; echo "Start $start_time<br/>"; echo "End $end_time<br/>"; ob_flush(); flush(); if (isset($_SESSION['views'])) { $_SESSION['views'] += 1; } else { $_SESSION['views'] = 0; } if ($_SESSION['views'] % 2 == 0) { echo "sleep 10 seconds<br/>"; sleep(10); } $allover_end_time = float_time(); echo "allover time elpased : " . ($allover_end_time - $allover_start_time) . "<br/>"; echo "The page views: " . $_SESSION['views']; ?>
php session
Morgan cheng
source share