30 分钟后从数据库中删除项目 [英] deleting item from database after 30 minutes
问题描述
我想要一个脚本,它可以计算我网站上有多少用户在线,但是这个脚本应该计算访客,所以我为会话创建了一个数据库,这个脚本为用户提供了一个 ID 并设置了 30 分钟的会话,以及现在我有一个问题,因为如果他超过30分钟不活跃,他应该从数据库中删除,因为我想通过ID统计有多少用户在线,我很头疼我该怎么做.>
有没有简单的方法可以做到这一点?
如 Barmar 在 他们的回答:
<块引用>从 my_table 中删除WHERE 时间戳
写一个执行这个SQL的PHP脚本,并添加一个crontab条目每 30 分钟运行一次.或者使用 MySQL Event Scheduler 运行定期;它在这里有描述.
I want to have a script, that counts how many users are online on my site, but this script should count guests, so I have created a database for session, this script gives user an ID and set 30 minutes session, and now I have a problem, because if he is not active more than 30 minutes, he should be deleted from the database, because I want to count by ID how many users are online, and I have headache how can I do this.
Is there a simple way to do this?
As stated by Barmar in their answer here:
DELETE FROM my_table WHERE timestamp < NOW() - INTERVAL 30 MINUTE
Write a PHP script that executes this SQL, and add a crontab entry that runs it every 30 minutes. Or use the MySQL Event Scheduler to run it periodically; it is described here.
这篇关于30 分钟后从数据库中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!