When the browser requests the same PHP file, the latter request is blocked by the previous request, is there any way to not block it?

Source: Internet
Author: User
When the browser requests the same PHP file, the latter request is blocked by the previous request, is there any way to not block it?
For example, request simultaneously
a.php
Sleep (10);
echo ' Hello ';
Exit

Subsequent requests will not be executed until after 10s.

If both a.php and b.php are requested, they are executed at the same time.

b.php = = a.php

Reply content:

When the browser requests the same PHP file, the latter request is blocked by the previous request, is there any way to not block it?
For example, request simultaneously
a.php
Sleep (10);
echo ' Hello ';
Exit

Subsequent requests will not be executed until after 10s.

If both a.php and b.php are requested, they are executed at the same time.

b.php = = a.php

There are two cases of this problem:

First: If the session is opened and the session is saved with a file, the session file is locked before the last script is processed, causing the next script to wait until the lock is acquired.

Second: If you use multiple tabs of the same browser to access the same URL at the same time, the browser considers the different requests to be the same person, queues each of your requests, and does not do concurrent processing. Whether Nginx or Apache, are in concurrent processing, but your browser took the liberty to block your request, it looks as if the server does not support concurrency, in fact, otherwise. Using IE6 ~ IE8 These low-level browsers will not have this phenomenon .

The main script obviously does not use the session, so the first case can be ruled out. For the second case, this is the browser design problems, and temporarily did not find a solution, if anyone knows please tell me, thanks

Landlord said wrong, the first request will block 10s, but does not affect the second one, each request a process.
It's not nodejs.

To know how the browser submits the request to PHP, it is not usually PHP that handles the request first, but Apache. Apache will then establish a process to transfer requests to PHP, so there will be no blocking unless you are using a normal HTTP service.

PHP has built a CLI HTTP Server for development testing starting from 5.4:
Php-s 127.0.0.1:8080-t/www
The CLI HTTP server is a single-process application that only processes one request at a time, and subsequent requests are queued.
This is true if you only open a Php-fpm/apache prefork mpm work process.

Sleep (10) This 10-second operation is obviously inappropriate by the PHP process that is providing the Web service, because it is sure to cause a PHP worker process to be blocked. Consider using Popen or PROC_ Open asynchronously invokes a CLI program, such as a PHP script under a CLI, for some time-consuming operations.

Like what:
/www/index.php


  
   

/www/cli.php

#!/png/php/5.4.39NTS/bin/php 

index.php并不会被10秒的操作阻塞,10秒的操作交给cli.php执行了,从而实现了异步.

我猜测你的问题是由于session写锁导致的,试试在sleep前加上session_write_close(); 看是否依然出现阻塞,可参见这篇文章:http://blog.csdn.net/haozi3156666/article/details/39502381, 是国外的某人写的

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.