天天看点

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

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

打开其它页面都没问题,只有这个页面有问题,应该是那个页面的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下,条件语句中访问常量数组会出问题(未有全面测试,仅从本案例得到结论,不一定准确)。

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

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',              

} elseif (isset($this->BEYOND_WIDGET[$name])) {            

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