I use $ajax
requests in many parts of my PHP website everything was working perfectly until few days ago all my $ajax
requests start giving error 500 - internal server error
.
I can see that error in the console and also I used error handler to get more information about the error.
That is my Ajax request
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);
that is what i get on my browser:
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);
?>
Some Notes:
1. It is not giving this error all the time sometimes it works fine and bring the response correctly (I see the response and header information on the website and when I check network tab in the chrome console).
2. it does not matter if the type is GET OR POST it keeps giving me the same problem (I show this ajax example with GET type but I have also POST type requests in my website with the same problem).
3. I add the ini_set('display_errors',1);``ini_set('display_startup_errors',1);``error_reporting(-1);
to the start of the is_it_midnight.php
but no errors showed because i believe there is no syntax or any other php errors (because sometimes it works fine and correctly).
4. I check also the server error log but there is nothing related to this files or any other ajax file at all.
5. I tried to check if this is a timeout error but I did not get any timeout
from textStatus
it just alert error
.
UPDATE :
I checked apache log and I found something like this: [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
I need any useful help or clue to understand why do I get this error is there anything I did not try it to get more information about that error???