I am not awesome enough to create a chat application, and I am looking to get someone to work, and I have lately downloaded one from here, it's very good to date, as I have examined it on XAMPP, but I've got a slight problem. I am attempting to generate a listing of online customers allow it a far more request-like feel, the main problem with this, is I have no idea how to get it done easily.

When customers login to my website, a session named g_username is produced, (the chat states 'username', but I'll fix that) and from things i see to date, the simplest method is always to store their username inside a database known as OnlineUsers and call that data via Ajax, but, another problem, is the fact that it's session based, and often the customers can just leave, without logging out, and that i meant to operate a script to logout the consumer from both OnlineUsers table, by removing the session.

When they leave without logging out, they'd be online forever! I possibly could potentially suffix a little of code on every page, that toggled an ajax event on-page close, the big event as being a script that kills their OnlineUsers table record, however again, that will load the server with useless queries as customers jump between pages, so far as I am aware.

Creating my entire site in Ajax is not really a choice, as it is a lot of various sites combined directly into 1 'place' having a social 'layer' (for a moment) from the social service.

Does anybody see a method to do that that will seem sensible, and become simple to integrate, and use Apache, without command line access?

you might have a cron job [for those who have cpanel] running around the server once every 60secs approximately, that inspections whenever a user last sent anything through the chat when they haven't within the last allows say 5mins then remove their entry in the online customers list.

You can so something similar to storing a timestamp from the customers last action inside a database, evaluating that timestamp when outputting online customers and ensuring it had been done for the most part 1 min ago.

Operate on all/vital pages: (Determining when the last action is outdated, you might see if it had been accomplished for about a minute ago to lessen the database-load)

if($user['lastAction'] < time()) {
   //update into database, last action is outdated

When calculating the quantity of customers on the internet and is at the loop of every timestamp

//If the users last action was within a minute, the user is most likely online    
if(($row['lastAction']- time()) > 60*60)
       //count user as online