昨天,一個(gè)程序需要導(dǎo)出500條數(shù)據(jù),結(jié)果發(fā)現(xiàn)到150條是,Nginx報(bào)出504 Gateway Timeout錯(cuò)誤
經(jīng)觀察,發(fā)現(xiàn)大約30秒時(shí)超時(shí),php.ini中執(zhí)行時(shí)間配置已經(jīng)是300秒:
代碼如下:
max_execution_time = 300
再查nginx的相關(guān)配置,無(wú)果。
寫(xiě)了一個(gè)php的測(cè)試頁(yè)再測(cè):
代碼如下:
echo 'aaa';
set_time_limit(0);
sleep(40);
echo 'aa';
依然超時(shí),可以確定set_time_limit這個(gè)函數(shù)沒(méi)生效。
再查php-fcgi的配置php-fpm.conf,下邊這個(gè)設(shè)置疑似有問(wèn)題:
代碼如下:
<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è)置的時(shí)間內(nèi)如果php還沒(méi)執(zhí)行完,則走此處的配置,也就是request_terminate_timeout=30秒。
先把這個(gè)參數(shù)改的和php中set_time_limit值一樣,都是300秒,還不行,不理解為什么,如果高手知道請(qǐng)賜教。
最終把request_terminate_timeout關(guān)閉,程序可以正常執(zhí)行了,問(wèn)題解決:
代碼如下:
<value name="request_terminate_timeout">0s</value>
補(bǔ)充:如果前端的nginx服務(wù)器使用了upstream負(fù)載均衡,那個(gè)負(fù)載均衡配置中以下幾個(gè)參數(shù)也需要相應(yīng)修改:
代碼如下:
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
新聞熱點(diǎn)
疑難解答
圖片精選