PHP session processing when the same client requests the same script several times in a row

So here is my test setup:

session_start();
if(!isset($_SESSION['bahhhh']))
    $_SESSION['bahhhh'] = 0;
$_SESSION['bahhhh']++;
sleep(5);
die('a'.$_SESSION['bahhhh']);

I expect that every time I click on the page, it returns a different number.

But if I use several tabs and update them every 5 seconds after the first, they all return the same number. (This is not client-side caching, as the 5 second delay is still obvious.)

Why is he doing this and how to fix it?

It seems to have the same weird caching problem with files and database data, and this prevents me from creating a working mutex to prevent the same code from being run more than once at a time.

Here is another simpler example:

echo microtime();
sleep(10);

Run it 3 times, every 2 seconds, and all three return the same microsecond. WTF?

+3
3
+6

script - , , script , . , - , .

, microtime(), , php , .

0

Apparently this is some bug in my browser. Opera behaves as long as Internet Explorer does not. I did initial testing in IE with the same results, but with more complex code. Apparently, this complex code had an error that caused the wrong behavior in IE, and this simplified code does not. Sorry to bother everyone.

0
source

Source: https://habr.com/ru/post/1734949/


All Articles