繁体   English   中英

php7在Ajax中出现错误500

[英]Error 500 in ajax with php7

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

当我在php5中执行完全相同的请求时,没有更多错误。 当我在没有ajax的新选项卡中的php7中执行完全相同的请求时,没有更多错误。 奇怪的是,当我有时在代码中添加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

您是否知道可能出什么问题?

我发现了问题,在我使用的代码中的某个地方有一个自定义异常,默认情况下它启动了一个带有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中并且仅在特定条件下存在,而且我没有时间去发现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM