Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Setting method of PHP execution time under PHP-Fcgi

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "PHP-Fcgi under the PHP execution time setting method", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "PHP execution time setting method under PHP-Fcgi"!

In general, set the timeout for PHP script execution

First, set it in php.ini

Max_execution_time = 1800

Second, set it through the ini_set function of PHP

Ini_set ("max_execution_time", "1800")

Third, set it through the set_time_limit function

Set_time_limit (1800)

The setting method of execution time of PHP under PHP-Fcgi

Yesterday, a program needed to export 500pieces of data and found that it was 504Gateway Timeout errors reported by Nginx

After observation, it is found that the timeout is about 30 seconds, and the execution time configuration in php.ini is already 300 seconds:

The copy code is as follows:

Max_execution_time = 300

Check the relevant configuration of nginx again, and there is no result.

Write a test page of php and retest.

The copy code is as follows:

Echo 'aaa'

Set_time_limit (0)

Sleep (40)

Echo 'aa'

If you still time out, you can be sure that the set_time_limit function does not work.

Check the configuration php-fpm.conf of php-fcgi again. There seems to be something wrong with the following setting.

The copy code is as follows:

30s

Check the official document: http://php-fpm.org/wiki/Configuration_File

The copy code is as follows:

Request_terminate_timeout-The timeout (in seconds) for serving a single request after which the worker process will be terminated. Should be used when 'max_execution_time' ini option does not stop script execution for some reason. Default: "5s". Note:'0s' means' off'

The main idea is that within the time set by set_time_limit in php, if the php has not been executed, then go to the configuration here, that is, request_terminate_timeout=30 seconds.

First change this parameter to the same value as the set_time_limit in php, which is 300 seconds. I don't understand why. If the master knows, please let me know.

Finally, the request_terminate_timeout is closed, the program can be executed normally, and the problem is solved.

The copy code is as follows:

0s

Add: if the front-end nginx server uses upstream load balancing, the following parameters in that load balancing configuration also need to be modified accordingly

The copy code is as follows:

Proxy_connect_timeout 300s

Proxy_send_timeout 300s

Proxy_read_timeout 300s

Thank you for your reading, the above is the content of "PHP execution time setting method under PHP-Fcgi". After the study of this article, I believe you have a deeper understanding of the PHP execution time setting method under PHP-Fcgi, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report