Notify every 2 hours if new data is entered

Asked

Viewed 35 times

0

I’m trying to create a system so that the Cron run a PHP file every 2 hours, and check if there has been any record inserted in a given table, if there are new records, know the total amount of new records in the meantime.

The only approach I thought of was to consult with a COUNT, save the amount of records to a new table and then run the query that will send the notification if you have new records.

The question is: Is this approach ideal? Is there something easier or even more correct?

  • 1

    What if I delete a record and then create a new one? The total will be the same. In that case it would be more necessary to check if there is an id larger than the previous one.

  • Um, really, I hadn’t thought about it. I’ll see what I do, and thank you!

1 answer

1


Your Approach works, but if the previous table has some input time datetime field for you whenever you run the cron take the last executed time and query records from that time, if you have records after the last execution date, will be new records. cron saves a log whenever it is run, from to take the log date, and run from there on!

Browser other questions tagged

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