I am working on a website that is much like an online exam, and I want to devise a way so that I can indicate to the users that currently whether they are connected or disconnected to my servers. For this, I am constantly pinging an empty file on my server to know whether the connection is available. The code looks like this -
$(document).ready(function(){
//Defining the function
var req = function () {
$.ajax({
url : 'ping.php',
error: function(){$("#circle").css("background","red");},
complete : function () {
$("#circle").css("background","green");
req();
}
});
};
//Calling the function
req();
//Rest of my code
});
Now my understanding is that as long as the call completes, the circle will be green, and if an error occurs, it will turn red, and the Ajax calls will stop. My question is as follows:
Is there any 'better' way to do this? For example, how does Google or Facebook mark out their online users?
Will this recursive Ajax Call bring down/ slow down my server in any way?
Note: It is not actually 'my' server. I do not have administrative rights, so that is a major concern here.
Please help me out here. Thanks!