0
I need to check changes in my database and create a script that sends requests every millisecond by calling a function that returns the number of lines in that database, but I realized that it is a very wrong way to do this because it makes my system heavy and with my test hosting runs out the limit of database queries in a short time. There is another way to perform 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 running 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>
I believe you need Websockets to proceed with your implementation, where the server will notify the client about changes
– André Roggeri Campos