When the browser requests the same PHP file, the last request will be blocked by the previous request. Is there any way to avoid blocking?

Source: Internet
Author: User
When the browser requests the same php file, the last request will be blocked by the previous request. Is there any way to avoid blocking? For example, if you request a. php & amp; lt; at the same time ;? Phpsleep (10); echo & #039; hello & #039; exit; the subsequent requests will be executed after 10 s. If both a. php and B. php are requested, when the browser requests the same php file at the same time, the latter request will be blocked by the previous request. Is there any way to avoid blocking?
For example
A. php
Sleep (10 );
Echo 'hello ';
Exit;

The subsequent requests will be executed after 10 seconds.

If you request both a. php and B. php, the request is executed simultaneously.

B. php = a. php

Reply content:

When the browser requests the same PHP file, the last request will be blocked by the previous request. Is there any way to avoid blocking?
For example
A. php
Sleep (10 );
Echo 'hello ';
Exit;

The subsequent requests will be executed after 10 seconds.

If you request both a. php and B. php, the request is executed simultaneously.

B. php = a. php

There are two problems:

First, if the SESSION is enabled and the SESSION is saved as a file, the SESSION file is locked before the previous script completes processing, causing the next script to be in the waiting state before obtaining the lock.

Second, if you use multiple tabs in the same browser to access the same URL at the same time, the browser considers these different requests to be the same person and queues each of your requests, no concurrent processing is performed. Both Nginx and Apache are processed concurrently,However, your browser makes your own claim and blocks your requests. It seems that the server does not support concurrency, but it is not. Use IE6 ~ IE8 is not applicable to low-level browsers..

The script of the subject obviously does not use the SESSION, so the first case can be ruled out. In the second case, this is a browser design problem and no solution has been found yet. If anyone knows, please let me know, thanks

If the landlord says wrong, the first request will block 10 s, but it will not affect the second one. Each request has one process.
This is not nodejs

You need to know how the browser submits a request to PHP. Generally, it is not PHP that processes the request first, but apache. After that, apache will establish a process to send requests to PHP, so there will be no blocking, unless you are not using a normal HTTP service.

PHP has built a cli http Server for development and testing since 5.4:
Php-S 127.0.0.1: 8080-t/www
Cli http Server is a single-process application. Only one request can be processed at a time, and subsequent requests must be queued.
This is also true if you have only enabled one PHP-FPM/Apache Prefork MPM worker process.

Sleep (10) This 10-second operation is handled by the PHP process that is providing Web services. This is obviously not suitable because it will certainly cause a PHP workflow to be blocked. in this case, you can use popen or proc_open to asynchronously call a CLI program such as a PHP script under the CLI for some time-consuming operations.

For example:
/Www/index. php


  

/www/cli.php

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

Index. php is not blocked by 10 seconds of operation. 10 seconds of operation is handed over to cli. php for execution, thus implementing asynchronous.

I guess your problem is caused by the session write lock, try to add session_write_close () before sleep; to see if there is still blocking, see this article: http://blog.csdn.net/haozi3156666/article/details/39502381, written by someone outside of China

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.