2017-04-03 87 views
0

我将我的网站从php5.5切换到php7,我现在有一个非常奇怪的错误:当我做一个特定的ajax请求包含重定向时,服务器回答一个http 500错误代码,同时返回好的html内容(我可以从Chrome控制台中看到它)。错误500在ajax与php7

当我在php5中完成相同的请求时,我没有更多的错误。当我在没有Ajax的新选项卡中执行完全相同的请求时,我没有更多的错误。而陌生人,当我有时在我的代码中添加一个var_dump时,我没有更多的错误。

当我有500错误代码,我没有在我的日志中提到,并没有错误显示在HTML内容中。

这里是响应头蒙山错误:

HTTP/1.1 500 Internal Server Error 
Date: Mon, 03 Apr 2017 10:44:20 GMT 
Server: Apache 
Expires: Tue, 04 Apr 2017 10:44:20 GMT 
Accept-Ranges: bytes 
Set-Cookie: PHPSESSID=25e73849544a66f7512533246cde4d21; path=/ 
Last-Modified: Mon, 03 Apr 2017 10:44:20 GMT 
Content-Length: 11718 
Connection: close 
Content-Type: text/html; charset=utf-8 

无误(之后我添加的var_dump):

HTTP/1.1 200 OK 
Date: Mon, 03 Apr 2017 10:45:44 GMT 
Server: Apache 
Vary: Accept-Encoding 
Content-Encoding: gzip 
Content-Length: 3223 
Keep-Alive: timeout=5, max=100 
Connection: Keep-Alive 
Content-Type: text/html; charset=UTF-8 

做哟有可能是错误的任何想法?

+0

请务必检查正确的日志文件(S),也即你有PHP配置摆在首位,以记录错误。 – CBroe

+0

我有很多警告和通知,我忽略了(如果我不再忽略它们,我可以看到它),但没有错误。 这是我的日志配置: '的error_reporting(E_ALL&〜E_NOTICE&〜E_STRICT&〜E_WARNING&〜E_DEPRECATED);' 'set_exception_handler();' '的set_error_han dler();' 'debug_backtrace(); ' '的ini_set( 'html_errors',真);' '的ini_set( 'display_errors设置',1);' '的ini_set( 'display_startup_errors',1);' 编辑:不知道如何在一个更好的格式代码评论SRY – Yrtiop

+0

把你的问题相关的代码 – hassan

回答

0

我发现这个问题,在我用至极推出,默认为500 HTTP错误头的代码某处一个自定义异常,但头球被异常推出后的脚本没有被杀,于是就出现了很难找到它:

public function __construct($message = "Critical error", $code = 500, Exception $previous = Null) { 
    parent::__construct($message, $code, $previous); 
    if($this->getHttpHeader()) 
     header($this->getHttpHeader()); 
    } 

    public function getHttpHeader() { 
    $header = get_header_for_code($this->getCode()); 
    $this->http_header = $header; 
    return $this->http_header; 
    } 

但我仍然不知道为什么这个问题只是在PHP7,只有在一定条件下,我没有时间去寻找。