How to monitor changes in the database without making abusive queries

1

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

    
asked by anonymous 10.01.2018 / 01:38

2 answers

2

You can use Triggers .

Trigger is a procedure that is invoked before or after a DML request, update , or delete ) happens. It is important to note that trigger is always attached to a table. In the circumstance presented would fall perfectly its use.

In short, you will have to create a trigger for each insert or delete command in the table to control the rows.

    
10.01.2018 / 02:10
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 is complicated 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, that's what you need.

    
10.01.2018 / 05:30