skip to Main Content

I need to check the database if a new row is created for the user and show him a popup message. I should do it for every user, and it should happen without refreshing the page (Live). Shall I try pusher/socket or make Ajax call every 5 seconds? I really want to use Ajax because it’s easier and straightforward.
The related table has nearly 50,000 rows, and I’ll need to check if a new row with the particular user_id is added through a postback.

3

Answers


  1. Since the information needs to be transmitted from the server (at some unknown time) to the client, it would be far more elegant to use a WebSocket (JS docs). This way, instead of the client having to repeatedly ping the server, the client just has to establish a socket connection once, and the server can send the data whenever it’s ready.

    Login or Signup to reply.
  2. you can try setInterval function in JS for call Ajax function.

    function checkAjaxFunc() { ... }
    setInterval(function() {checkAjaxFunc()},5000); 
    
    Login or Signup to reply.
  3. Why not a scheduled task?
    See here

    You could set a cache value every five second and in ajax call read only this value. in this way you will not read DB and only a cache value every 5 seconds instead of once every 5 seconds for each user logged in

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search