PHP MySQL,如果时间超过存储时间5分钟以上 [英] PHP MySQL if time is 5 minutes more or over then the stored time

查看:148
本文介绍了PHP MySQL,如果时间超过存储时间5分钟以上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要存储在数据库中的时间戳与当前时间之间的差值为5分钟或更长时间,我想让脚本删除该行。

I want to the script to delete the row if the difference between a timestamp that is stored in the db and the current time is 5 minutes or more.

示例

db中的一行具有2011/12/25 10:00

当前时间为2001/12 / 25 10:06

A row in db has 2011/12/25 10:00
the current time is 2001/12/25 10:06

我希望它删除数据库行。

I want it to remove the db row.

推荐答案

为什么cron建议?您可以在每个页面视图上轻松调用非常简单的delete语句。目前已成为瓶颈(然后我们谈论的是表工程结构严重不足或站点非常繁忙),因此了解查询为何如此缓慢的原因可能是合适的。运行一个解释查询,应用一些索引,等等。如果问题仍然存在,则可能是因为太多的工作让访客等待,然后是cron的时候了。

Why the cron suggestions? You can easily call the very easy delete statement on every page view. At the moment that becomes a bottlenecks (and then we're talking about either a massively underengineered table structure or a very busy site), it may become appropriate to see why the query is so slow. Run an explain query, apply some indexes, and so on. If the problem then still exists, it could be that it's simply too much work to let a visitors wait for, and then it's time for cron.

在此之前,只需执行在每个页面视图上执行以下查询:

Until then, simply execute the following query on each page view:

delete 
from 
    YourTable 
where 
    adddate(YourDateTimeColumn, interval 5 minute) < now()

这篇关于PHP MySQL,如果时间超过存储时间5分钟以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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