I need to check changes in my database and I created a script that sends requests every millisecond by calling a function that returns the number of rows in that database, but I realized that it is a very wrong way to do this because it leaves my heavy system and with my test hosting the query database limit is exhausted in a short time. Is there another way to perform the real-time update of the number of rows in the database table without sending multiple check requests?
My php function:
switch ($acao) {
case 'quantia':
$PDO = conectar();
$SG = $PDO->prepare("SELECT * FROM telas");
$SG->execute();
$result = $SG->fetchAll();
$bata = count($result);
echo $bata;
break;
Js executing the looping:
<script type="text/javascript">
function checar() {
$.ajax({
method: "POST",
dataType: 'html',
url: "functions/checagem.php",
data: 'acao=quantia',
success: function(resultado){ $('#oi').html(resultado); }
})
}
setInterval("checar()", 1)
</script>