我需要一个数据库更新时彗星刷新 html 的示例!

发布于 2024-10-31 01:16:14 字数 194 浏览 3 评论 0原文

大家,

我正在开发一个网页,每次数据库更新时都需要刷新。我已经在我的 PHP 代码中完成了 checkDatabaseUpdate() 。

但现在我确实需要一些帮助来开发一个简单的彗星来等待响应,另一个来检查更新。

有没有人有任何简单的例子来帮助我?

comet 是正确的解决方案吗?

谢谢,

People,

I am developing a web page that need to be refresh everytime that the data base gets an update. I already have the checkDatabaseUpdate() done in my PHP code.

But now I reaaly need some help to develop a simple comet to wait for a response, and another to check for update.

Is there anybody with any simple example to help me?

Is comet the right solution for that?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

高跟鞋的旋律 2024-11-07 01:16:14

您想说的是,数据库在后端执行查询(INSERT、UPDATE、DELETE),并且您希望在执行该查询时刷新用户的首页?

嗯..使用 jQuery(循环)来“Ajax 检查”前端控制器中的数据库更新,然后刷新。

function refreshPage () {
   $.load('checkModifDb.php', function(response, status) {
        if .... { do the trick here - check jquery load.api }
   }
});

and then use setInterval( "refreshPage()", 10000 ); to run the function every 10 seconds and 
refresh only if it founds that db was modified.

我现在想不出任何东西,但我想只需稍加修改,你就可以做到这一点。 twitter.com 就是这样做的。

What you want to say is that on the database are executed querys (INSERT, UPDATE, DELETE) in the backend and you want to refresh the front page of a user when that query`s are executed ?

Hmm .. use a jQuery (looping) to "Ajax check" for database update in the frontcontroller and then refresh.

function refreshPage () {
   $.load('checkModifDb.php', function(response, status) {
        if .... { do the trick here - check jquery load.api }
   }
});

and then use setInterval( "refreshPage()", 10000 ); to run the function every 10 seconds and 
refresh only if it founds that db was modified.

I can't think of anything right now but i guess with little modification you shoul do the trick. This is how twitter.com do it.

遮云壑 2024-11-07 01:16:14

comet 是正确的解决方案吗?

由于 PHP 的工作方式(让 Web 服务器守护进程处理传入请求),将其与长轮询技术相结合可能会导致服务器不满意。每个连接的用户都将保持与 Web 服务器守护程序的连接。根据该守护程序的配置,您可能会发现 comet 是针对您自己的服务器的有效拒绝服务攻击。

您可能会更好地使用简单的旧的短暂的 ajax 轮询。

Is comet the right solution for that?

Because of the way that PHP works (having a web server daemon process incoming requests), combining it with long-polling techniques can make for an unhappy server. Each connected user is going to hold open a connection to the web server daemon. Depending on that daemon's configuration, you may find that comet is an effective denial of service attack against your own server.

You'd probably be better off with plain old short-lived ajax polling here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文