【发布时间】:2015-12-09 16:57:46
【问题描述】:
我在我的 PHP 网站的许多部分都使用了$ajax 请求,直到几天前我所有的$ajax 请求都开始提供error 500 - internal server error。
我可以在控制台中看到该错误,并且我使用错误处理程序来获取有关该错误的更多信息。
那是我的 Ajax 请求
window.setInterval(function(){
$.ajax({
type: "GET",
url: "include-ajax/is_it_midnight.php",
dataType: "json",
success: function(data)
{
if(data == 1)
{
//Reload website at midnight
location.reload();
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
alert(textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
}
});
}, 10000);
这就是我在浏览器上看到的:
is_it_midnight.php:
<?php
$current_hour = date('H');
$current_minute = date('i');
$current_second = date('s');
//If the website was open between the 00:00:00 and 00:00:10 it will refresh automatically
//else it will not be open it will open after midnight so it will have aleardy the new day data
if($current_hour == 0 && $current_minute == 0 && ($current_second > 0 && $current_second < 10))
{
$is_it_midnight = 1;//This flag means it is midnight
}
else
{
$is_it_midnight = 2;//This flag means it is not midnight
}
echo json_encode($is_it_midnight);
?>
一些注意事项:
1. 它不是一直给出这个错误,有时它可以正常工作并正确带来响应(我在网站上看到响应和标题信息,当我在 chrome 控制台中检查网络选项卡时)。
2. 类型是 GET 还是 POST 都没有关系,它总是给我同样的问题(我用 GET 类型展示了这个 ajax 示例,但我的网站中也有 POST 类型的请求,有同样的问题)。
3. 我将ini_set('display_errors',1);``ini_set('display_startup_errors',1);``error_reporting(-1); 添加到is_it_midnight.php 的开头,但没有显示错误,因为我相信没有语法或任何其他php 错误(因为有时它可以正常工作)。
4. 我还检查了服务器错误日志,但根本没有与此文件或任何其他 ajax 文件相关的内容。
5. 我试图检查这是否是超时错误,但我没有从textStatus 得到任何timeout 它只是提醒error。
更新:
我检查了 apache 日志,发现如下内容:[Sat Feb 21 07:35:05 2015] [error] [client 176.40.150.195] Premature end of script headers: is_it_midnight.php, referer: http://www.example.com/index.php
我需要任何有用的帮助或线索来了解我为什么会收到此错误,有什么我没有尝试过以获取有关该错误的更多信息吗???
【问题讨论】:
-
只需检查您的 PHP 错误日志。
-
你检查你的 Apache 错误日志了吗?
-
@showdev 是的,这就是我所说的。这个错误并没有一直显示给我。我试图理解为什么它有时会显示???
-
你确定你找对地方了吗?这看起来更像是访问日志条目而不是错误日志条目。
标签: php ajax apache http internal-server-error