1

Let's say i have an ajax function in my js code. I am going to use jQuery.

function ajaxcall(a, b) {
    $.ajax({
        method: "POST",
        url: "example.php",
        data: {
            n: a,
            y: b
        }
    }).done(function(msg) {
        alert("Data Saved: " + msg);
    });
}

var interval=setInterval(ajaxcall("Dany", 20), 60000);

I'll call this function once per minute and basicly when i change interval time to 500 it will do 120times/minute, thats 120 users.

var interval=setInterval(ajaxcall("Dany", 20), 500);

The thing is that i know how to prevent multiple calls in my php file, but the problem is that the server must respond every time and that means my server is obligated to work and to process something.

In my php file, i have 6 lines of code which will detect every unneeded call. and 6 lines are almost nothing, but the call exists.

My question is: How much these types of calls are going to harm my server s performace? Is it something I should worry about?

sorry for my bad english I hope you understand my question. thanks

  • Nothing to worry about. There's always caching. – Andrei Dec 06 '16 at 11:39
  • Try it out - it might be not practical if you will have really heavy traffic... as well if you get 'slower' then you can always change server to nginx if using apache... as well think about websockets and socketo.me if you're interested in real time communication without making 400 api calls... – Tom St Dec 06 '16 at 12:41
  • @Andrew i dont understand whats that mean "there's always caching" –  Dec 06 '16 at 13:00
  • what is your purpose of making too many AJAX calls. – Aabir Hussain Dec 07 '16 at 11:58
  • @AabirHussain if someone change my js script in his browser for example as a said in my post `var interval=setInterval(ajaxcall("Dany", 20), 500);` kind a hack –  Dec 07 '16 at 12:06
  • I am sorry but i got confuse here **I'll call this function once per minute and basicly when i change interval time to 500 it will do 120times/minute, thats 120 users.**. – Aabir Hussain Dec 07 '16 at 12:37
  • If 120 request coming from 120 users, then its fine but if 120 request made by single user then it may be danger. Are you using CSRF token or some thing similar to prevent hacks – Aabir Hussain Dec 07 '16 at 12:39
  • @AabirHussain yea as i said in my post `The thing is that i know how to prevent multiple calls in my php file`, in 6 lines of code it will detect every other inneeded call and process will die() –  Dec 07 '16 at 12:48
  • @AabirHussain i'll call this function my site is going to call this function once per minute but what if hacker change this to call 120 times per minute you know –  Dec 07 '16 at 12:49

1 Answers1

0

As answer By Alsciende here.

Max Number of default simultaneous persistent connections per server/proxy:

Firefox 2:  2
Firefox 3+: 6
Opera 9.26: 4
Opera 12:   6
Safari 3:   4
Safari 5:   6
IE 7:       2
IE 8:       6
IE 10:      8
Chrome:     6

So, you don't have any need to worry. But is case you want to avoid multiple calls to that particular function.

You can use session to store user id, time of the call made through ajax. Send user id with every ajax call match user id and check last call time and then make your condition.

Hope this would help you

Community
  • 1
  • 1
Aabir Hussain
  • 1,161
  • 1
  • 11
  • 29