Bas*_*sel 5 php apache ajax http internal-server-error
我$ajax
在PHP网站的许多部分都使用了请求,直到几天前所有$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);
Run Code Online (Sandbox Code Playgroud)
那就是我在浏览器中得到的:
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);
?>
Run Code Online (Sandbox Code Playgroud)
一些注意事项:1.有时并非总是出现此错误,有时它可以正常工作并正确显示响应(我在网站上以及在chrome控制台中检查“网络”标签时看到了响应和标头信息)。2.不管类型是GET还是POST都不会给我同样的问题(我向ajax示例展示了GET类型,但我的网站中也有POST类型的请求也有同样的问题)。3.我在ini_set('display_errors',1);``ini_set('display_startup_errors',1);``error_reporting(-1);
的开头添加了,is_it_midnight.php
但未显示任何错误,因为我认为没有语法或其他任何php错误(因为有时它可以正常运行)。4.我还检查了服务器错误日志,但与此文件或任何其他ajax文件完全没有任何关系。5.我会尝试检查,如果这是一个超时错误,但我没有得到任何timeout
来自textStatus
它只是警告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 进程被服务器终止(我怀疑使用了mod_fastcgi / mod_fcgidphpinfo()
;您可以使用 检查这一点)。此外,您每 10 秒执行一次调用,这可能会达到某个限制。对于你的情况我会做什么:
mod_fastcgi
/ mod_fcgid
(Server API
中的字段phpinfo()
)。access_log
是否存在模式。500
is_it_midnight.php
setInterval
刷新时间增加到15s、20s、25s、30s等,看看是否有改善。error_log (memory_get_usage());
前面echo json_encode($is_it_midnight);
查看分配给脚本的内存使用量是多少(尽管对于小脚本来说内存使用量不太可能成为问题)。