如何连续监视mysql数据库中的表并触发php脚本以对其进行处理? [英] How to continuously monitor a table in a mysql database and triger a php script to work on it?

查看:120
本文介绍了如何连续监视mysql数据库中的表并触发php脚本以对其进行处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是监视mysql中的一个表,该表始终由sms网关自动更新.

What I want to do is to monitor a table in mysql which is always auto-updated by a sms gateway.

应该对脚本进行连续监视,并且表中一旦有新条目,就会触发编写用于执行进一步操作的php脚本.

The script should be monitored continuously and as soon as there is a new entry in the table, a php script ritn to perform further operations should be triggered.

我该如何实现?

推荐答案

我已经使用cron做了很多次.因此,您的php脚本首先查看是否有新条目,然后执行是否需要做的事情.如果没有任何工作,它会立即退出.要记住的一件事是,如果脚本需要很长时间才能运行,则需要确保您的cron作业已相应设置,因此它们不会重叠.

I've done exactly this lots of times using cron. So your php script starts by seeing if there is a new entry, and then does what it needs to do if there is. If there's nothing to work on, it just exits immediately. One thing to bear in mind is that if the script takes a long time to run, you want to make sure your cron jobs are set accordingly, so they don't overlap.

实现此目的的一种简单方法是在表中有一个特殊列,该列指示该行是否已被php脚本检查过.因此,当php脚本运行时,它将查找具有该字段false的所有数据.像这样:

One simple way to achieve this is to have a special column in the table which indicates whether the row has been examined by the php script or not. So when the php script runs, it looks for all data that has that field false. Something like this:

SELECT id from my_table where dealt_with = FALSE;

然后在这些行上运行时,将对其进行更新:

And then when it's run on those rows, it updates them:

UPDATE my_table set dealt_with = TRUE where id=1234;

这篇关于如何连续监视mysql数据库中的表并触发php脚本以对其进行处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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