1. 程式人生 > >php-fpm超時時間設置request_terminate_timeout分析

php-fpm超時時間設置request_terminate_timeout分析

http狀態碼 允許 另一個 efault script RM time sleep 實驗

之前發現一個php配置之後關於返回500和502的問題,今天看到一個兄弟寫的非常不錯,記錄一下。 php日誌中有一條超時的日誌,但是我request_terminate_timeout中設置的是0,理論上應該沒有超時時間才對。 PHP Fatal error: Maximum execution time of 30 seconds exceeded in ... OK,先列出現在的配置: php-fpm: request_terminate_timeout = 0 php.ini: max_execution_time = 30 先查閱了一下php-fpm文件中關於request_terminate_timeout的註釋 ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the ‘max_execution_time‘ ini option ; does not stop script execution for some reason. A value of ‘0‘ means ‘off‘. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 這個註釋說明了,request_terminate_timeout 適用於,當max_execution_time由於某種原因無法終止腳本的時候,會把這個php-fpm請求幹掉。 再看看max_execution_time的註釋:這設置了腳本被解析器中止之前允許的最大執行時間,默認是30s。看樣子,我這個請求應該是被max_execution_time這個設置幹掉了。 好吧,不死心,做了一個實驗:
php-fpm request_terminate_timeout 設置 0 15
php.ini max_execution_time 設置 30 30
執行結果 php有Fatal error超時日誌,http狀態碼為500 php無Fatal error超時日誌,http狀態碼為502,php-fpm日誌中有殺掉子進程日誌
好吧,結論是web請求php執行時間受到2方面控制,一個是php.ini的max_execution_time(要註意的是sleep,http請求等待響應的時間是不算的,這裏算的是真正的執行時間),另一個是php-fpm request_terminate_timeout 設置,這個算的是請求開始n秒。

php-fpm超時時間設置request_terminate_timeout分析