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 e
My guess is that the PHP process is killed by the server due to some (mis)configuration on your host (I suspect that mod_fastcgi/mod_fcgid is used; you can check this with phpinfo()). Also, you execute the call on each 10 seconds which could hit some limit. What I would do in your case:
mod_fastcgi/mod_fcgid (Server API field in phpinfo()).access_log and see if a pattern exists for 500 status code for script is_it_midnight.php.setInterval refresh time to 15s, 20s, 25s, 30s and etc. to see if there is any improvement.error_log (memory_get_usage()); before echo json_encode($is_it_midnight); to see what is the memory usage allocated to the script (although it is very unlikely that the memory usage is a problem given the small script).