Edit:
I changed the name from "Why can't the second client access the page until the first call ends?" to "Why does the second client from the same IP address have a 20 second timeout before displaying the page?". Thus, until all changes are changed,
here are 2 urls:
/homeand /sleep.
/home displays the home page
/sleep sleeps 10 seconds
I have 2 clients:
Client 1 : /sleep→ 10 seconds waiting
Client 1 : /sleep, Client 2 : /home→ 1 client waits 10 seconds, Client 2 Instant Download page.
1: /sleep, 2: /sleep → 1 10 , 2 20 .
? ?
- , - .
:
$fileHandler = fopen('process.lock', 'w');
$hasLock = flock($fileHandler, LOCK_EX | LOCK_NB);
if (!$hasLock) {
return('already running'); // it never goes here.
}
for ($i = 0; $i < 10; ++$i) {
echo nl2br("$i" . PHP_EOL);
ob_flush();
flush();
sleep(1);
}
flock($fileHandler, LOCK_UN);
fclose($fileHandler);
. , " " 20 . , for, " " 2, 20 .
, .
Edit2
, , Apache PHP, , :
1 /sleep:
public function sleep() {
sleep(300);
}
, 2 :
public function sleep() {
die('hello');
}
5 ( ), 20 hello.
Edit3
1: 127.0.0.1/sleep → 10
2: 192.168.0.10/sleep → 10
, IP. ?