PHP - Real Time Application [closed]

3

A doubt

I need to make an application that validates from time to time if a session is valid through a query to the bank. This query should be done automatically, without the need for a user action, such as a JS location.reload ().

I thought of using a php socket to do this validation, but I do not know if it is the right way. Or change the whole idea and abandon the php and use the nodeJs that seems to be more useful for this functionality.

Could someone explain to me the best way to develop this application? I just need a guide to use, not coding or scripting, it's more the same conceptual question and showing the correct way forward.

    
asked by anonymous 07.12.2017 / 12:33

1 answer

1

Follow the sketch below in js and php.

I do not see the need to use socket or nodejs, when a simple request and setInterval can solve your problem.

JS:

$(document).ready(function () {
    setInterval(validaSessao , 5000);
});
function validaSessao(){
    $.ajax({
        method:'post',
        url: 'validaSessao.php',
        async: true,
         dataType:'json',
        success: function (retorno) {

            console.log(retorno);
        }


    });
}

PHP:

$stmt = $conn->prepare("");
$stmt->bindParam('', $nome, PDO::PARAM_STR);
$res = $stmt->execute();
echo json_encode($res);
    
07.12.2017 / 16:36