谁在 Pylons 在线 [英] Who's Online in Pylons

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

问题描述

我目前有一个 Pylons 应用程序,它运行着基本的用户系统设置.我想尝试创建一个小部件来显示当前登录到网站的用户.我不确定我应该如何处理这个问题;我不确定 pylons 会话是否处于活动状态是基于用户是否实际上在 Web 应用程序页面上,所以我正在寻求一些关于如何使用我已经拥有的可能来完成此任务的想法.

I currently have a Pylons application running with a basic user system set-up. I want to try and create a widget that shows the users that are currently logged on to the website. I'm not sure how I should handle this though; I'm not sure if pylons sessions being active are based on whether or not a user is actually on the web apps page or not, so I am seeking some ideas as to how I can work with what I already have possibly to accomplish this.

推荐答案

有几种方法可以做到,具体取决于您想要达到的准确程度.

There's several ways you can do it, depending on how accurate you want to be.

最简单的第一种方法是使用 memecached 或持久存储来跟踪用户,以及他们上次点击页面的时间.考虑任何在 X 分钟内点击页面的人都被登录",只要他们没有退出".如果您只是在每次点击页面时更新数据库,或者更新 memcached(或更快的数据库),然后在最后一分钟内查询会话.

The easiest, and first way to do it, use memecached or a persistent store to keep track of users, and the last time they hit a page. Consider anyone that has hit a page within X minutes to be 'logged in', as long as they're not 'logged out'. If you just update the db every page hit, or update memcached (or faster db), then query it for sessions within the last minute.

第二,但在您的服务器上更加密集,将 Javascript 放在每个页面上,每 XX 秒/分钟点击您网站上的一个特殊 URL 以指示用户已登录.记录并使用该计数.这样做的好处是您的 JS 可以使页面上的计数器实时更新.尽管轮询在您的服务器上可能很昂贵.

Second, but more intensive on your server, put Javascript on every page, that hits a special URL on your site every XX seconds/minutes to indicate the user is logged in. Record that, and use that count. This has the advantage that your JS could keep the counter on the page up to date in real-time. Though the polling might be expensive on your server.

或者第三,使用 Comet 风格的系统,比如 Orbited,只要用户在连接到服务器的页面上,连接就会打开,你可以跟踪你有多少打开的会话.我相信 Orbited 每台服务器一次可以处理大约 10k 个打开的连接.

Or third, use a Comet style system, say with Orbited, and as long as the user is on a page connected to the server, the connection will be open, and you can track how many open sessions you have. Orbited can handle around 10k open connections at a time per server I believe.

我推荐第一种类型,因为它需要最少的额外开销/设置并处理相当常见的情况.如果您使用实时聊天需要更高的准确性,请考虑另外两种之一.

I'd recommend the first type as it requires the least extra overhead/setup and handles the fairly common case. If you're using real-time chat where you need more accuracy consider one of the other two.

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

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