Reputation: 9952
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!
Upvotes: 3
Views: 2983
Reputation: 501
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);
}
}
Upvotes: 2
Reputation: 4075
You can use comet
library for this.
http://ajaxian.com/archives/comet-with-php
http://www.zeitoun.net/articles/comet_and_php/start
Upvotes: 1