如何在一段时间后触发mysql事件? [英] How to trigger mysql event after a time period?

查看:51
本文介绍了如何在一段时间后触发mysql事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 mysql 数据库,用于存储在线用户.是否有一种有效的方法可以在一段时间后触发事件以检测不活动的用户(将其状态设置为离线")?我将用户上次活动的时间存储在表中(TIMESTAMP 值).

I have a mysql database that stores users that are online. Is there an efficient way of triggering an event after a time period to detect the users that are inactive (to set their status to "offline")? I'm storing the last time the user was active in a table (TIMESTAMP value).

谢谢!

推荐答案

要定期运行 php 脚本,您有很多解决方案:

To run a php script regularly, you have many solutions :

  • 您使用了 cron 作业(这意味着您有一台服务器).要了解如何执行此操作,您可以访问此链接.
  • 您使用 MySQL 提供的事件调度程序.
  • 如果您没有服务器,您可以使用会定期启动您的任务的提供程序,最著名的是 Webcron.org(它不是免费的).
  • 其他解决方案,您创建一个 PHP 脚本,该脚本将在后台运行,同时等待执行操作的正确时间;为此,您必须有权访问函数 set_time_limit()ignore_user_abort().然后您创建一个脚本,该脚本不断循环并检查当前是否有事情要做.
  • You use a cron job (this implies that you have a server). For learn to do this you can visit this link.
  • You use the Event Scheduler provided by MySQL.
  • If you not have server, you can use a provider who will launch your tasks regularly, the most known is Webcron.org (it's not free).
  • Other solution, you create a script PHP that will run in the background while waiting for the right time to perform an action ; for do that you must have access to function set_time_limit() and ignore_user_abort(). Then you create a script that loops continuously and checks for the moment whether there is something to do.

这篇关于如何在一段时间后触发mysql事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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