0

I want to add online/offline system to my project, but I'm confused with the best method to do it.

On login and log out, it's easy to update the column online on the database with false or true

User Table:

---------------------------
| ID |   Email   | online |
---------------------------
| 1  | test@g.co |    0   |
---------------------------
| 2  |  te@g.be  |    1   |
---------------------------

But the problem is when the user closes the browser without sign out, how I can update the online column with false?

So, I thought by using an ajax running every 4 or 5 min, to call a function checking if users stay online or no.

But I think that this method is not professional, and it can be heavy on the website (to run a script) can make the website slow.

Is there any best method to do this ?

sayou
  • 893
  • 8
  • 29

1 Answers1

1

But I think that this method is not professional

It's a standard approach.

and it can be heavy on the website (to run a script) can make the website slow.

One HTTP request every 5 minutes to call a simple "I'm alive" script is not going to be remotely heavy.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • but to call of HTTP request it's not one, but it's related with the number of visitors if they're 1000 users, so it 1000 HTTP request every 5 minutes, for that I'm confused and I don't know if that can make the website slow or not – sayou Apr 23 '19 at 10:26
  • 1
    And how many *other* (mostly much heavier) HTTP requests will those 1000 users be making while they are active on the site? A 5 minute keep alive script is a drop in the ocean. – Quentin Apr 23 '19 at 10:29
  • A good analogy sir, Thanks for your reply sir – sayou Apr 23 '19 at 10:30