[error] readv() failed (104: Connection reset by peer) while reading upstream,
client: x.x.x.x, server: host.tld, request: "POST /script.php ..."
request_terminate_timeout,FPM 強制殺掉 Worker 進程# php-fpm.conf 或 www.conf
request_terminate_timeout = 600 # 秒,預設通常 30s 或 0(關閉)
# 同步調整 Nginx 超時
# nginx.conf http/server/location 區塊
fastcgi_read_timeout 600s;
proxy_read_timeout 600s;
| 層級 | 參數 | 建議值 | 說明 |
|---|---|---|---|
| PHP-FPM | request_terminate_timeout | 600s | 單一請求硬性終止時間 |
| PHP-FPM | request_slowlog_timeout | 10s | 慢日誌觸發閾值 |
| PHP | max_execution_time | 300 | php.ini 腳本執行上限 |
| Nginx | fastcgi_read_timeout | 600s | 等待 FastCGI 回應 |
| Nginx | proxy_read_timeout | 600s | 反向代理等待上游 |
| Nginx | client_body_timeout | 60s | 讀取請求體超時 |
slowlog = /var/log/php-fpm-slow.logrequest_slowlog_timeout = 5sxdebug / tideways / blackfire 剖析效能瓶頸不要只調大超時!**必須**找出慢查詢根因優化。超時設定是安全網,不是解決方案。長跑任務請改用佇列 (Redis/RabbitMQ) + Worker 非同步處理,HTTP 請求只負責分發任務並即時回應。
# 重載配置
systemctl reload php-fpm
nginx -s reload
# 模擬長跑請求測試
curl --max-time 610 "https://example.com/long_task.php"
# 應正常返回結果,而非 502/504