开发者

how to implement server pushing when there is an update in mysql database?

开发者 https://www.devze.com 2023-02-10 06:51 出处:网络
the situation i\'m facing is: i have a php+mysql web application. several users share resources in the same database.

the situation i'm facing is:

i have a php+mysql web application. several users share resources in the same database. i want to implement a feature that whenever there is a change for database records(create,update or delete), other users will be notified instantaneously.

I'm considering to use ajax push engine (APE), but not sure how the big picture is.

(1) is it something like i need a script constantly checking the last_update timestamps and send notifications to client when a new change is detected?

OR

(2) every time after performing any operation to database table, send notification to clients, telling them to reload data?

which one is be开发者_如何学运维tter or any other suggestions on how to implement this?

thanks in advance!


Your best option is #2, when you write to the database that is when your change is happening, that is when you should push.

class DatabaseModel
{
    ...

    function save($data)
    {
        ... // your db query

        after_save();
    }

    function after_save()
    {
        // push changes out using some other object 
        // e.g. MyPushClass::something_changed($this);
    }
}


You can use comet library for this.

http://ajaxian.com/archives/comet-with-php

http://www.zeitoun.net/articles/comet_and_php/start

0

精彩评论

暂无评论...
验证码 换一张
取 消