I am trying to integrate node.js app into an existing PHP/MySQL system. node-mysql is used to allow node.js to access the MySQL database. A table named tableA in the MySQL database updates with new data every 10 minutes.
Problem: Using node, I need the node server to continuously check tableA for changes whenever tableA gets updated. What is a good way to achieve this?
I am thinking if I used setInterval(checkDb(tableA), 10*60*1000), or an infinite loop, the checkDbquery function may not coincide with the database update.
I also happen to be using socket.io so will a good method be for the PHP system to emit('dbUpdated') to the node server if it is even possible for PHP to send a message to node.js?
Node Code
var dbCheckQueue = function(callback) {
client.query('SELECT * from tableA',
function(error, results, fields) {
if error
throw error;
callback(results);
});
}
// 10mins-interval checking of table
setInterval(function() {
dbCheckQueue(function(results) {
console.log('Fresh meat!')
});
}, 10*60*1000);