Can anyone cite examples for a user’s status? (online & offline)

Asked

Viewed 600 times

1

So I was thinking of picking up the user table where the status = online, I put by default "Offline" , but I know that when the user shuts down the computer without clicking Log out, the table will not be changed for offline, then I want to know what’s best:

  • DATETIME

  • TIMESTAMP

Which ones do you recommend me? I want to do data with "Last activity" where if it does any action that involves $_GET or $_POST updates the table status (I will convert to TIMESTAMP or DATETIME) to X minutes ago or something like that, I want examples so I won’t put my DATABASE in question here. Grateful for all opinions, and commented examples.

(I still don’t understand how services like Gmail, Facebook and others make this relationship between offline and online, so if someone also has the good will to explain this, welcome)

  • the logic is simple, as you can see in the answers below.. The problem is the technique used. Many use asynchronous requests via ajax from the client side. This causes a congestion of requests when the site has a considerable volume of unique access. Depending on the device that accesses, for example, an iPhone, the device heats up in less than 1 minute. The recommendation is to use long pooling. Search on Node.js

3 answers

1

Look the answer is very simple. There is no type of click check or anything like that done on the page. The simplest way is to check the time the user accesses the system and make a comparison of 1 minute or less with the current time if it is out more than 1 minute for example it appears offline. For this to work you create a routine that updates the user’s schedule while online on the page in this way if it stays out for more than 1 minute when other users check it will appear offline through this time comparison.

1

Good evening Kevin, man I already did this in one of my first projects (a social network mobile) when I was 16 years old. The answer is very simple, every time a logged-in user interacts with the site (changing or updating the page itself) you call a function or method responsible for going in the database and updating some field of some table with exact date of interaction. In your script before calling this function you run a second function that checks whether in the table that stores the last accesses of each user if the current time is X minutes longer than the last saved in the table positive case depresses user, negative case updates table using the first function cited above.

When it comes to showing other users who is online, just make a SELECT in the database listing all users who have the last access saved in until the X minutes allowed.

Tip: To make it more scalable, you can create a third function that will restrict these queries/recordings in the bank, caching the last access of each user to not be demanding too much of the bank. Only if you have good traffic on your site, otherwise you can only use the simple solution I pointed out.

I hope I helped, hug.

1


Use TIMESTAMP I believe that it will be easier for you to interact in your system without errors. Gmail seems to do this check with the user’s mouse pass (mouseover), because when you are for example in chat he is normal, "online", but when you go to another tab and passes a x minutes absent from the chat tab then he will consider you as "inactive". After you move your mouse over some element of the site then it should send a command to the server saying "Look, Kevin is still available, so let’s change his status to online".

  • 1

    All right, I understand rsrs. But instead of "clicking" on the body I find it easier to move the mouse in the body, because sometimes the user will return the page and just move the mouse and will not click anything. Passing the mouse, at least the user on the other side will know that it is currently in that tab.

  • It would be a good thing if you did something similar to Google, with polka dots, "green" or "ash". If you create 10 minutes = inactive, 15 minutes = offline, for the end user you may get confused. Imagine that I am "green" and I leave the system, it passes 10 minutes then it will give as "absent" being that I already left and not only was absent, then the user on the other side will think "he is still here, Jaja he comes back" and that is not what will happen rsrs. With balls it is easier for the user to understand. It is either ON or OFF. If it comes back then it is "green" automatically.

  • You can use jQuery to update a part of the code for you from x in x seconds. Or if you have patience, but a lot of patience try to see Ode.js is a great way out. Look for Long Polling. A reference http://imasters.com.br/artigo/23436/javascript/veja-como-o-long-polling-pode-te-ajudar-a-desenvolver-aplicacoes-em-tempo-real/

  • I get it. Then look for how to make a "PHP Chat" and pay attention as they do to update the content without needing the user to do it himself. So you take the logic and put it in yours. Some use <meta> of HTML, other setTimeOut() jQuery.

  • hey, got an idea, setInterval for a function, and do . load user status.

  • Try it this way, maybe it will work. See jQuery, maybe it will help you in what you need ;)

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.