来自同一客户端的异步请求处理

I'm using Docker to test an application locally. It uses this Dockerfile which uses nginx and php-fpm. You can see the nginx configuration here.

I would like to create a lock file when the first request comes in, and throw an error for subsequent requests while the first request processing is in progress. However I cannot test the behavior when using a second tab or window in the same browser when sending the second request.

As a simple test in my controller I put a sleep(5); return 'hello';.

When I access the app locally it works fine, but I will always wait until processing is finished if I access the page from the same browser. For example if I have four windows open:

  1. Chrome (normal)
  2. Chrome (normal)
  3. Chrome (incognito)
  4. Firefox

And I go to the page that has the sleep in it, firing the requests at about the same time, then 1, 3 and 4 will complete after 5 seconds, but 2 will wait until 1 is finished and will take 10 seconds.

It looks like that the same browser will open a connection to the same port which will be busy for 5 seconds for the second request. Is it possible to change this behavior so that all requests are handled asynchronously? It seems to be because the other three requests are handled asynchronously, but I don't know why requests from the same browser are not.