Tutorial :PHP/JS/JQUERY: Smart method to Auto check/updating a points status



Question:

So right now I am using me of this:

function checkpoints()  {     var postThis = 'checker.php?userid='+ $('#user_id_points').val();    $.post(postThis, function(data){          $(".vispoints").html(data).find(".vispoints1").fadeIn("slow")    });    setTimeout(checkpoints, 5000);  }  

This function repeats each 5 seconds (sending request each 5 seconds) and running the checker.php each 5 seconds, to show how many points you got. (checker.php echo out how many points you've got in a span class vispoints1).

Now isnt there a smarter method doing this, instead of sending requests like this all the time.. I mean sites like facebook and that, they dont do like this to check if you e.g got a new friend request?

Hope you can help me find a better method examples would be good too.


Solution:1

I mean sites like facebook and that, they dont do like this to check if you e.g got a new friend request?  

Actually, sites like Facebook do employ polling to get certain notifications. If you're using Firefox, install the Live HTTP Headers plugin and you'll see timed calls to facebook servers.

For your app, polling every 5 seconds is far too much. Scale it back to every couple of minutes. Anything that requires that much "granularity" shouldn't be using javascript but rather a different language that can open a port on the server.


Solution:2

You can look into the ideas which can be found by searching for keywords like

Comet, Ajax Push, Reverse Ajax, ....


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »