How to monitor database changes without making abusive queries

Asked

Viewed 287 times

1

I have a code that accesses the database every second and returns me the number of rows of a table, the problem is that an abusive number of requests and queries are made in the database to monitor changes in the lines, I need something that monitors changes in the database and returns only the result when there are changes in the number of lines, how can I do this ?

2 answers

2


You can use Triggers.

Trigger is a procedure that is invoked before or after a DML request (Insert, update or delete) happen. It is worth mentioning that the Trigger is always attached to a table. In the presented circumstance would fall perfectly its use.

In short, you will have to create a Trigger for each command Insert or delete table, in order to control the lines.

1

One possibility would be to use sockets, that is, keep the communication channel open, to avoid making new requests (with high frequency). Although it’s tricky to use in shared hosting. Perhaps the best solution for you is to use some push notification service, such as parse, although it is laborious to implement in php and javascript. In conjunction with @Altieri’s response, it’s what you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.