Nginx PHP-Fcgi中因PHP執(zhí)行時間導(dǎo)致504 Gateway Timeout錯誤解決記錄
昨天,一個程序需要導(dǎo)出500條數(shù)據(jù),結(jié)果發(fā)現(xiàn)到150條是,Nginx報出504 Gateway Timeout錯誤
經(jīng)觀察,發(fā)現(xiàn)大約30秒時超時,php.ini中執(zhí)行時間配置已經(jīng)是300秒:
max_execution_time = 300
再查nginx的相關(guān)配置,無果。
寫了一個php的測試頁再測:
echo 'aaa';
set_time_limit(0);
sleep(40);
echo 'aa';
依然超時,可以確定set_time_limit這個函數(shù)沒生效。
再查php-fcgi的配置php-fpm.conf,下邊這個設(shè)置疑似有問題:
<value name="request_terminate_timeout">30s</value>
查官方文檔:http://php-fpm.org/wiki/Configuration_File
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'
大意是php中set_time_limit設(shè)置的時間內(nèi)如果php還沒執(zhí)行完,則走此處的配置,也就是request_terminate_timeout=30秒。
先把這個參數(shù)改的和php中set_time_limit值一樣,都是300秒,還不行,不理解為什么,如果高手知道請賜教。
最終把request_terminate_timeout關(guān)閉,程序可以正常執(zhí)行了,問題解決:
<value name="request_terminate_timeout">0s</value>
補(bǔ)充:如果前端的nginx服務(wù)器使用了upstream負(fù)載均衡,那個負(fù)載均衡配置中以下幾個參數(shù)也需要相應(yīng)修改:
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
相關(guān)文章
基于Xen的VPS ubuntu+nginx+php安裝教程
跟蹤vps已經(jīng)很久了,但是因?yàn)樾枰厥舛丝陂_服務(wù),所以符合條件的多為Xen平臺的vps。眾多比較之后選擇了vpslink在西雅圖機(jī)房,速度還不錯。2010-07-07Nginx做NodeJS應(yīng)用負(fù)載均衡配置實(shí)例
這篇文章主要介紹了Nginx做NodeJS應(yīng)用負(fù)載均衡配置實(shí)例,本文直接給出配置實(shí)例,需要的朋友可以參考下2015-01-01Nginx中l(wèi)imit_req模塊和limit_conn模塊的使用
本文主要介紹了Nginx中l(wèi)imit_req模塊和limit_conn模塊的使用,通過limit_req和limit_conn模塊,可以有效實(shí)現(xiàn)精確的請求頻率和連接數(shù)控制,下面就來具體介紹一下2024-05-05