I want to delete a user from database and destroy the session after he has been idle for some time, lets say 5 mins. How can I do that ? For starters, how to check if the user is idle? I need it mainly for when a user closes the browser he would be deleted from database. But it would be a big bonus if I can delete him even when the browser is still open but he has not done anything. I have a little chatroom and it I have a table that holds which user is in which room. When the user closes the browser, I need to delete him from that table. Ask if something is unclear. Thanks.