Home  >  Article  >  Backend Development  >  How to set timeout in php-fpm

How to set timeout in php-fpm

藏色散人
藏色散人Original
2021-05-24 09:05:373335browse

php-fpm How to set timeout: 1. Set the content "request_terminate_timeout = 30"; 2. Set the content "max_execution_time = 30".

How to set timeout in php-fpm

The operating environment of this article: nginx1.0.4 system, PHP7.1 version, DELL G3 computer

php-fpm nginx timeout parameter setting

php-fpm:
request_terminate_timeout = 30
php.ini:
max_execution_time = 30

request_terminate_timeout is suitable for when max_execution_time cannot terminate the script for some reason, this php-fpm request will be killed.

The execution time of web request PHP is controlled by two aspects, one is max_execution_time of php.ini (it should be noted that sleep, the time for http request to wait for response is not counted, here is the real execution time) , the other is the php-fpm request_terminate_timeout setting, which counts n seconds since the request started.

When this time is exceeded, PHP-FPM will not only terminate the execution of the script,

will also terminate the Worker process that executes the script. Therefore, Nginx will find that the connection to communicate with itself is broken, and will return a 502 error to the client.

The key parameters of nginx are fastcgi related timeout, namely: fastcgi_connect_timeout, fastcgi_read_timeout, fastcgi_send_timeout.

The subjects of these nginx parameters are all nginx, so fastcgi_connect_timeout means the timeout time for nginx to connect to fastcgi, fastcgi_read_timeout is the timeout time for nginx to read the content of fastcgi, and fastcgi_send_timeout is the timeout for nginx to send content to fastcgi. overtime time.

Nginx 504 Gateway Time-out means that no executable PHP-CGI was requested.

Nginx 502 Bad Gateway means that the requested PHP-CGI has been executed, but the PHP-CGI process was terminated because the resource reading was not completed.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set timeout in php-fpm. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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