# recv() failed
## 報錯內容:
>2020/03/13 12:10:34 [error] 31720#0: *2661487 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 67.229.103.26, server: www.dyhjw.com, request: "POST /api/getHqLastInfo HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi-56.sock:", host: "www.dyhjw.com"
## 說明:
之前解決過這個問題,現在這個問題又重現了。看了阿里云負載均衡常見問題,有了更清晰的認識,鏈接文章如下:[https://help.aliyun.com/knowledge\_detail/55207.html?spm=a2c4g.11174283.6.695.325e1192wftz5C](https://help.aliyun.com/knowledge_detail/55207.html?spm=a2c4g.11174283.6.695.325e1192wftz5C)
## 原因:
`PHP`腳本執行時間處理超時,即如果`php-fpm`處理`PHP`腳本的時長超過了`Nginx`中`request_terminate_timeout`設置的值,就會出現`502 Bad Gateway`的錯誤,同時在` Nginx`日志中可以查看到如下錯誤記錄
>[error] 1760#0: *251777 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: localhost, request: “GET /timeoutmore.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”
## 需要了解
參考文章:[https://blog.csdn.net/loophome/article/details/78604986](https://blog.csdn.net/loophome/article/details/78604986)
### 1、`php-fpm` 處理 `PHP`腳本時間,在哪里?
處理腳本的時間是:`max_execution_time`
位置在 `/www/server/php/56/etc/php.ini`

### 2、`nginx` 中的 `request_terminate_timeout` 的值是,在哪里?
答:`request_terminate_timeout` 配置在` php-fpm.conf` 中,位置在: `/www/server/php/56/etc/php-fpm.conf`
配置參數是: `request_terminate_timeout`
原先是`100`,我們更改為`300`:

## 錯誤分析:
原因是: `max_execution_time=300` 執行時間大于 `request_terminate_timeout=100` 執行時間
一般可能執行時間都是小于100的,但當于100的話就報錯!
## 解決方法
1、`php.ini` 把 `max_execution_time` 值調大一些,由 `300`調整為 `600`
2、`php-fpm.conf` 把 `request_terminate_timeout` 值調大一些,由 `100` 調整為 `0` (PS:0為無限制!)
## 涉及命令
1、`vim /www/server/php/56/etc/php.ini` 查找 `max_execution_time`
2、`vim /www/server/php/56/etc/php-fpm.conf` 查看 `request_terminate_timeout`
3、重新啟動 `php5.6`
- (一)服務器架構
- ECS
- (二)寶塔安裝
- 寶塔的webhook使用方法
- (三)配置更改
- php-fpm.conf
- proxy.conf
- nginx.conf
- (四)運維日志
- nginx日志
- nginx錯誤日志
- open socket
- fpm日志
- php-fpm錯誤日志
- seems busy
- slow.log
- 站點日志
- dyhjw.log
- 站點錯誤日志
- dyhjw.error.log
- 499錯誤
- recv()
- recv() failed
- recv() failed-第3種
- no live upstreams
- upstream prematurely
- cache_file_has_too_long_header
- FastCGI sent in stderr
- directory index of is forbidden
- recv() failed-第4種
- (五)站點配置
- appapi配置
- 用到redis的網站
- workman不能運行
- 快訊啟動
- dyhjw偽靜態
- (六)其他問題
- php-5.6重新啟動報錯
- 掛載盤命令
- 服務器怎么增加黑名單不讓指定IP登錄
- (七)自定義頁面
- 自定義404頁面
- 自定義502頁面
- (八)問題
- 負載均衡的文件在哪里
- 站點的負載均衡服務器文件在哪里
- 其他知識
- Nginx--keepalive的配置
- Nginx反爬蟲攻略:禁止某些User Agent抓取網站
- php腳本執行時間配置
- 運維記錄