Memcache+PHP 会话调整:memcache 如何使密钥过期?
更新,2011 年 10 月 24 日:我将其移至 ServerFault,这可能更合适,也是我最初打算将其发布的地方。然而,我找不到“移动到 SF”选项,所以真的,我只是将其复制到那里。任何人都可以帮助实际移动这个吗?
我对此做了一些研究,但还没有找到明确的答案。
我们有一个使用 PHP+Memcache 会话处理程序的 Web 应用程序。
我有几个相互关联的问题,但最终我的问题是,“为什么 PHP 会话在我们认为应该过期的时候却没有过期?”即最终用户应该在设定的时间后退出应用程序,但事实并非如此。
以下是要点,请帮我连接它们,并告诉我哪里错了:
- 我的理解是 Memcache 根据设置的时间(以秒为单位)(或较大值的 unix 时间戳)使键过期。
- 过期时间是惰性的——即不会提前删除任何内容
- PHP memecache 会话处理程序使用sessions.gc_max_lifetime 来设置memcache 键过期时间。我不知道,也许不是?
- Memcache 应该在服务请求的密钥并发现它已过期时不提供服务(然后也可能删除它?)。但至少不服务它。
- 对于 PHP 来说,这种不提供服务的行为应该等同于删除会话和用户注销。
用户不会被注销。
我该如何调试这个? Memcache 并不完全透明。
更新 我应该指定未运行的示例案例是会话超时设置为两个小时的站点。示例用户最后一次使用该网站是在晚上,然后 8 - 10 小时后返回该网站并仍然登录。
Update, 24OCT2011: I moved this to ServerFault, which is probably more appropriate and which is where I meant to post this in the first place. However, I couldn't find a "move to SF" option so really, I just copied it there. Can anyone help with actually moving this?
I've done some research into this and have not found a definitive answer.
We have a web app that is using the PHP+Memcache session handler.
I have several questions, all interrelated, but ultimately my issue is, "Why are PHP sessions apparently not expiring when we think they should be?" i.e. The end user should be logged out of the app after a set time, but is not.
Here are the dots, please help me connect them, and tell me where I am mistaken:
- My understanding is that Memcache expires keys based on the set time, in seconds (or unix timestamp for larger values).
- The expiration is lazy -- i.e. nothing is deleted in advance
- The PHP memecache session handler uses the sessions.gc_max_lifetime to set the memcache key expiration. idk, maybe it doesn't?
- Memcache should, on serving a requested key and seeing that it is expired, not serve it (and then maybe also delete it?). But at least not serve it.
- This act of not serving it should, to PHP, equate to a deleted session and the user being logged out.
Users are not being logged out.
How can I even debug this? Memcache isn't exactly transparent.
Update
I should have specified that the example case that has not been working is a site with a session timeout set to two hours. An example user would last use the site at night, and then, 8 - 10 hours later, come back to the site and still be logged on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终用户应在最后一次向服务器发出请求后的设定时间后从应用程序注销。。每次客户端发出请求时,其过期时间都会重置。如果过期时间为 3 分钟,并且您每 2 分钟发出一次请求,则您的会话永远不会过期。
The end user should be logged out of the app a set time after their last request to the server. Every time a client makes a request, his expiration resets. If the expiration is 3 minutes, and you make a request every 2 minutes, your session will never expire.