PHP会话超时回调? [英] PHP session timeout callback?
问题描述
我正在运行 PHP + APACHE + CENTOS Linux 组合.
I'm running a PHP + APACHE + CENTOS Linux combination.
我已经实现了登录 &登出网站.
I have implemented a login & logout on the website.
我的问题是,我怎么知道 php 会话何时超时(用户没有注销就关闭了浏览器)?
My question is, how can I know when the php session has timed-out (User has closed his browser without logging-out)?
原因是,当用户执行以下任何操作时,我想执行一些清理和/或数据库更新(调用另一个 PHP):(1) 退出或 (2) 超时
The reason is, I want perform some cleanups and/or database updates (calling another PHP) when the user has done any of the following: (1) LOGGED-OUT or (2) TIMED-OUT
我的猜测是我必须使用 Apache/Linux,对吗?
My guess is that I would have to make use of Apache/Linux, right?
推荐答案
您可以创建一个脚本,该脚本将以某种半固定的时间间隔运行(例如每 5 分钟一次,使用 crontab 作业),而不是检测 php 会话何时超时最有可能)将自动注销/执行对过去一小时(或任何您的超时值)未处于活动状态的任何人的清理.只需在您的用户表中添加一个lastseen".
Instead of detecting when the php session times out, you could create a script that will run at some semi regular interval (every 5 minutes say, using a crontab job most likely) that will log out/perform the clean up for anyone who hasn't been active in the last hour (or whatever your timeout value is) automatically. Just add a 'lastseen' to your user table.
这篇关于PHP会话超时回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!