问题
I've been using an HTTP POST to a php file to change entries in a given MySQL database. Essentially, the second the value changes, I would like the user that is viewing the database table to be notified. For now my temporary solution is to auto refresh a page displaying the table to keep it updated but I feel like there has to be a more efficient way of going about this.
回答1:
Do you really have to update it in the same second? It looks like a server killer feature.
Read about Comet, maybe it will be useful.
回答2:
IIRC mysql_affected_rows() will only report instances where the data has changed (i.e. if you try to update a row to its current values then it won't give an error).
I find it hard to believe that you've got someone watching a screen waiting for an update to occur - maybe a better approach would be to add a timestamp field to the record - but note that if you do this, and in the absence of other checks, the record will always update - to prevent make sure at least one of the fields has changed in the update.
C.
回答3:
When I had to do this, I created a one-row table containing the last time any relevant part of the database was updated. Then the once-per-second activity was confined to seeing if the contents of that one-row table showed newer than the local value; if so, refresh.
The one-row table could be updated via triggers from any table containing relevant facts, or from the application, as you think best.
回答4:
checkout pines notify i use it with ajax submitted changes
来源:https://stackoverflow.com/questions/3131326/effectively-notify-when-mysql-data-entry-changes