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

2.9k views Asked by At

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 better or any other suggestions on how to implement this?

thanks in advance!

2

There are 2 answers

0
Nik On
0
esfourteen On

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);
    }
}