PHP runs for too long and does not respond to other requests.

angryTom
Release: 2023-02-26 21:40:02
Original
2227 people have browsed it

PHP runs for too long and does not respond to other requests.

Don’t run PHP scripts that take more than ten minutes to run in PHP-FPM.

1. It is recommended that PHP scripts running in PHP-FPM use pclose(popen()) to open a PHP-CLI process without blocking to execute your script.

2. After the execution is completed, insert the message into the database.

3. The front desk performs message notification through AJAX scheduled polling (similar to Zhihu's message notification).

If you must run this kind of time-consuming script in PHP-FPM, it is not impossible.

First you need to configure Nginx to forward this script to a pre-configured independent PHP-FPM dynamic process pool (different PHP-FPM process pools listen to different ports) for processing, so that The execution of the script will not affect other PHP-FPM process pools. Moreover, the dynamic process pool (pm = dynamic) can dynamically fork out more processes to process scripts, at the cost of more memory consumption. In this case, you'd better configure a maximum number of processes (pm.max_children = 20).

If you want PHP-FPM to continue processing business after ending the HTTP request, you can use fastcgi_finish_request()This function provided by PHP-FPM.

Recommended: "PHP Tutorial"

The above is the detailed content of PHP runs for too long and does not respond to other requests.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template