10054: An existing connection was forcibly closed by the remote host

简介:
现象

打开页面,PHP-CGI退出,Nginx错误日志如下:

2017/08/09 15:13:31 [error] 8140#19268: *1 WSARecv() failed (10054: An existing connection was forcibly closed by the remote host) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /siteManager/template/templateEdit.html?id=1 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9090", host: "localhost:8202", referrer: http://localhost:8202/siteManager/template/templateList.html

原因

打开其它页面都没问题,只有这个页面有问题,应该是那个页面的PHP代码的问题。

通过排除法,确定是下面红色的代码导致:

if ($name == self::INPUT_HIDDEN) {            
elseif($name == self::INPUT_LARGE_FILE_UPLOAD) {            
elseif (isset(self::BEYOND_WIDGET[$name])) {            
elseif ($name == self::INPUT_RICH_EDIT) {            
else {            
}

常量BEYOND_WIDGET定义如下:

const INPUT_JSON = 'jsonEditor';            
const INPUT_RICH_EDIT = 'richEdit';            
const INPUT_HTML_CODE_EDITOR = 'htmlCodeEditor';            
const BEYOND_WIDGET = [            
self::INPUT_JSON => 'common\widgets\jsonEditor\JsonEditor',            
self::INPUT_IMAGE => 'common\widgets\inputImage\InputImage',            
self::INPUT_HTML_CODE_EDITOR => 'common\widgets\htmlCodeEditor\HtmlCodeEditor',            
];

另外,这个问题在PHP 7下是没有的,在PHP 5.6下出现。

简单总结一下,就是在PHP 5.6下,条件语句中访问常量数组会出问题(未有全面测试,仅从本案例得到结论,不一定准确)。

解决

既然常量不行,那就把常量改成变量:

const INPUT_JSON = 'jsonEditor';            
const INPUT_RICH_EDIT = 'richEdit';            
const INPUT_HTML_CODE_EDITOR = 'htmlCodeEditor';            
private $BEYOND_WIDGET = [              
self::INPUT_JSON => 'common\widgets\jsonEditor\JsonEditor',              
self::INPUT_IMAGE => 'common\widgets\inputImage\InputImage',              
self::INPUT_HTML_CODE_EDITOR => 'common\widgets\htmlCodeEditor\HtmlCodeEditor',              
];

if ($name == self::INPUT_HIDDEN) {            
elseif($name == self::INPUT_LARGE_FILE_UPLOAD) {            
elseif (isset($this->BEYOND_WIDGET[$name])) {            
elseif ($name == self::INPUT_RICH_EDIT) {            
else {            
}






本文转自 tywali 51CTO博客,原文链接:http://blog.51cto.com/lancelot/1954846,如需转载请自行联系原作者

目录
相关文章
|
5月前
|
监控 网络安全
Connection reset by peer的原因
Connection reset by peer的原因
|
5月前
|
应用服务中间件 nginx Docker
connect() failed (113: No route to host) while connecting to upstream
connect() failed (113: No route to host) while connecting to upstream
183 0
【已解决】kex_exchange_identification: Connection closed by remote host fatal: Could not read from
【已解决】kex_exchange_identification: Connection closed by remote host fatal: Could not read from
|
7月前
|
Go 开发工具 git
【git】解决:Failed to connect to 127.0.0.1 port 7890: Connection refused
【git】解决:Failed to connect to 127.0.0.1 port 7890: Connection refused
2090 0
|
Linux
七个办法只有一个有效:200 PORT command successful. Consider using PASV.425 Failed to establish connection.
七个办法只有一个有效:200 PORT command successful. Consider using PASV.425 Failed to establish connection.
638 0
七个办法只有一个有效:200 PORT command successful. Consider using PASV.425 Failed to establish connection.
执行HQL直接被退出:Remote side unexpectedly closed network connection
执行HQL直接被退出:Remote side unexpectedly closed network connection
1222 0
执行HQL直接被退出:Remote side unexpectedly closed network connection
|
Linux 网络安全
WARNING:The remote SSH server rejected X11 forwarding request.
WARNING:The remote SSH server rejected X11 forwarding request.
214 0
WARNING:The remote SSH server rejected X11 forwarding request.
|
网络安全
REMOTE HOST IDENTIFICATION HAS CHANGED问题解决
REMOTE HOST IDENTIFICATION HAS CHANGED问题解决
350 0
REMOTE HOST IDENTIFICATION HAS CHANGED问题解决
|
应用服务中间件 nginx
[error] 17755#0: *58522 readv() failed (104: Connection reset by peer) while reading upstream
[error] 17755#0: *58522 readv() failed (104: Connection reset by peer) while reading upstream
5089 0

热门文章

最新文章