检查mysql以进行长时间轮询 [英] checking mysql for long polling purposes

查看:208
本文介绍了检查mysql以进行长时间轮询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网站上进行一些长时间的轮询,以通知用户传入的邮件.我将使用mysql用于数据库目的.如果表有更新,检查mysql是否安全?这会导致网站变慢,因为它会不断寻找更新吗?您甚至会如何检查mysql是否已更新?

I'm trying to do some long polling on my site for notifying users of incoming mail. I would be using mysql for database purposes. Would it be safe to check mysql if there's an update to the table? Would this cause the site to slow down as it will constantly look for an update? How would you even check if mysql is updated?

代码看起来像这样

while($currentTime <= $lastTime){
     usleep(10000)
     clearstatcache();
     $sql = mysql_query("SELECT time FROM timestamp WHERE $currentTime = timestamp");
     $row = mysql_fetch_array($sql);
     $currentTime = $row['time'];
}

因此,基本上,它将一直运行直到数据库中出现新的时间戳为止,但这是否有效,它使服务器每10秒查看一次我的数据库?

So basically, it will keep running until theres a new timestamp in the database, but is this efficient where its making the server look into my database every 10seconds?

谢谢

推荐答案

您可以使用AJAX并让客户端每隔X秒轮询一次服务器.但是您可能会更详细地描述您的问题...

You could use AJAX and let the client side poll your server every X second. But you might describe your problem at a more detailed level...

cron可能是其他事情,但您必须提供更多信息.

Other thing possible is cron, but you'll have to provide more infos.

这篇关于检查mysql以进行长时间轮询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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