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

現象

打開頁面,PHP-CGI退出,Nginx錯誤日誌以下:html

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.htmljson

緣由

打開其它頁面都沒問題,只有這個頁面有問題,應該是那個頁面的PHP代碼的問題。數組

經過排除法,肯定是下面紅色的代碼致使:ide

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定義以下:this

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',            
];spa

另外,這個問題在PHP 7下是沒有的,在PHP 5.6下出現。日誌

簡單總結一下,就是在PHP 5.6下,條件語句中訪問常量數組會出問題(未有全面測試,僅從本案例獲得結論,不必定準確)。server

解決

既然常量不行,那就把常量改爲變量:htm

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 {            }

相關文章
相關標籤/搜索