PHP 接口调用报错 502 Bad Gateway

PHP接口调用超过5s的请求直接返回如下信息:

Response

<html> <head><title>502 Bad Gateway</title></head> <body bgcolor="white"> <center><h1>502 Bad Gateway</h1></center> <hr><center>nginx</center> </body> </html> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page -->

查了Nginx的错误日志如下:

2019/01/22 16:40:45 [error] 14291#0: *296842388 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 113.96.219.247, server: , request: "POST XXX HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php7-cgi.sock:", ...

原因是由于php_fpm的执行时间受request_terminate_timeout这个参数的配置影响,这个参数我配置的是5s,那么5s后,这个php-fpm处理进程会被直接杀掉,导致返回502

  • 官方备注:
    request_terminate_timeout mixed
    设置单个请求的超时中止时间。该选项可能会对 php.ini 设置中的 ‘max_execution_time’ 因为某些特殊原因没有中止运行的脚本有用。设置为 ‘0’ 表示 ‘Off’。可用单位:s(秒),m(分),h(小时)或者 d(天)。默认单位:s(秒)。默认值:0(关闭)。

    原文地址:http://www.bowen-tech.top/articles/detail/29

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值