0

I have a Javascript function that runs every 5 seconds and requests information from the same server via a jQuery AJAX call. The function runs indefinitely once the page is loaded.

For some reason the AJAX query is failing about once every minute or two, and showing

ERR_EMPTY_RESPONSE

in the console. The odd thing is, it fails for exactly 60 seconds, then starts working fine for another minute or two.

So far I've tried with no success:

  • Different browser
  • Different internet connection
  • Changing the polling time of the function. (Still fails for 60 second intervals. eg run every 10 seconds, it fails 6 times. Or 5x12 or 1x60)
  • Web searches which suggesting flushing ip settings on my computer

I never had any problem on my last server which was a VPS. I'm now running this off shared hosting with GoDaddy and wonder if there's a problem at that end. Other sites and AJAX calls to the server are working fine during downtimes though.

I also used to run the site over HTTPS, now it's over plain HTTP only. Not sure if relevant.

Here's the guts of the function:

var interval = null;
function checkOrders() {
interval = window.setInterval(function () {
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "http://www.chipshop.co.nz/ajax/check_orders.php",
      data: {shopid : 699},
      error: function(errorData) {
        //handle error
      },
      success: function(data) {
        //handle success
      }
    });
}, 5000); // repeat until switched off, polling every 5 seconds
}
Oli
  • 43
  • 1
  • 8
  • 1
    check the network tab and see what is the request and response properties... – Arun P Johny Mar 15 '16 at 07:36
  • Please share your controller code here, it looks like you using Magento – Abhishek Dhanraj Shahdeo Mar 15 '16 at 07:38
  • 1
    Not sure if it's relevant, but why do you use `POST` to check for orders? You aren't creating any new resources, you should use `GET` here – Max Filippov Mar 15 '16 at 08:27
  • @AbhishekDhanrajShahdeo Not using Magneto, just PHP. Have removed the PHP parts for clarity. – Oli Mar 15 '16 at 21:48
  • @maximf Good point - the example in jQuery docs used POST so I always used it also! – Oli Mar 15 '16 at 21:49
  • @ArunPJohny the network tab is returning status code 200 on successful AJAX calls along with the required info. On failed attempts, the following is shown in the Chrome network tab: `Request headers:Accept:application/json, text/javascript, */*; q=0.01 Content-Type:application/x-www-form-urlencoded; charset=UTF-8 Origin:http://www.chipshop.co.nz Referer:http://www.chipshop.co.nz/control-panel?shopid=699 User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36 X-Requested-With:XMLHttpRequest` - The status comes back as (failed) – Oli Mar 15 '16 at 21:50
  • Also on failed AJAX calls, the console is showing `POST http://www.chipshop.co.nz/ajax/check_orders.php net::ERR_EMPTY_RESPONSE Object {readyState: 0, responseText: "", status: 0, statusText: "error"}` – Oli Mar 15 '16 at 21:53
  • Hi, i am facing the same issue. did you get a resolution? – rrchrga Feb 12 '22 at 04:35

1 Answers1

3

Solved: It turned out the problem was with GoDaddy hosting. Too many POST requests resulted in the 60 second 'ban' from accessing that file. Changing to GET avoided this.

This page contains the answer from user emrys57 :

For me, the problem was caused by the hosting company (Godaddy) treating POST operations which had substantial response data (anything more than tens of kilobytes) as some sort of security threat. If more than 6 of these occurred in one minute, the host refused to execute the PHP code that responded to the POST request during the next minute. I'm not entirely sure what the host did instead, but I did see, with tcpdump, a TCP reset packet coming as the response to a POST request from the browser. This caused the http status code returned in a jqXHR object to be 0.

Changing the operations from POST to GET fixed the problem. It's not clear why Godaddy impose this limit, but changing the code was easier than changing the host.

Community
  • 1
  • 1
Oli
  • 43
  • 1
  • 8
  • It actually blocks the whole website from working for anyone until that 1 minute ban is over. Sounds like an easy way for anyone to take down a GoDaddy website by continuing to send POST data to the website. This is not acceptable for any Host. – PHPGuru Sep 12 '20 at 21:32
  • I meant it only bans our ip address and any computer that has that ip address. – PHPGuru Sep 12 '20 at 23:07