生成在线用户列表? [英] Generate a list of online users?

查看:94
本文介绍了生成在线用户列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还不足以编写一个聊天应用程序,并且我正在尝试让它工作.最近我从

I'm not awesome enough to write a chat application, and I'm trying to get one to work, and I've recently downloaded one from here, it's pretty good so far, as I've tested it out on XAMPP, but I have a slight problem. I'm trying to generate a list of online users to give it a more practical application-like feel, but the problem with that, is I have no clue how to do it easily.

当用户登录到我的网站时,将创建一个名为g_username的会话(聊天显示为用户名",但我会解决该问题),到目前为止,最简单的方法是存储他们的名为OnlineUsers的数据库中的用户名,并通过Ajax调用该数据,但是,另一个问题是,它是基于会话的,有时用户可以直接退出而无需注销,我打算运行一个脚本来从这两个用户中注销用户在线用户表,然后删除会话.

When users login to my site, a session named g_username is created, (the chat says 'username', but I'll fix that) and from what I see so far, the easiest method would be to store their username in a database called OnlineUsers and call that data via Ajax, but, the other problem, is that it's session based, and sometimes the users can just leave, without logging out, and I intended to run a script to logout the user from both the OnlineUsers table, and by deleting the session.

如果他们没有注销就离开,他们将永远在线!我可能会在每个页面上添加一些代码,从而在页面关闭时切换一个ajax事件,该事件是一个脚本,该脚本会杀死其OnlineUsers表记录,但随后,当用户在页面之间跳转时,它将为服务器加载无用的查询据我所知.

If they leave without logging out, they'd be online forever! I could potentially suffix a bit of code on every page, that toggled an ajax event on page close, the event being a script that kills their OnlineUsers table record, but then again, that would load the server with useless queries as users jump between pages, as far as I'm aware.

在Ajax中创建我的整个网站并不是真正的选择,因为它是将来自社交服务的多个不同网站组合成1个地方"和一个社交图层"(如果愿意)的方式.

Creating my entire site in Ajax isn't really an option, as it's a load of different sites combined in to 1 'place' with a social 'layer' (if you will) from a social service.

有人能在没有命令行访问的情况下找到一种有意义且易于集成并与Apache兼容的方法吗?

Does anyone see a way to do this that would make sense, and be easy to integrate, and do with Apache, without command line access?

推荐答案

您可以执行以下操作:将用户上次操作的时间戳记存储在数据库中,在输出在线用户时比较该时间戳记,并确保最多完成该操作1分钟前.

You could so something like storing a timestamp of the users last action in a database, comparing that timestamp when outputting online users and making sure that it was done at most 1 min ago.

在所有/重要页面上运行: (确定最后一个操作是否已过时,您还可以检查一分钟前是否已完成操作,以减少数据库负载)

Run on all/vital pages: (Deciding if the last action is outdated, you could also check if it was done for one minute ago to reduce the database-load)

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

在计算在线用户数量时,并且在每个时间戳的循环之内

When calculating the amount of users online and is within the loop of each 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

这篇关于生成在线用户列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆