I want my page to consistently check if the user session is still active. if using event listener. My concern is that php file execution time is limited. is there way to set php execution to infinite? or is there a better way of doing this?
JS:
$(document).ready(function() {
var loginSource = new EventSource("/structure/ajax/check_login_session.php");
loginSource.addEventListener("login-verification", function(e) {
var response = JSON.parse(e.data);
if (data.login_failed) {
login_fail_redirect();
}
});
})
php
function send_response() {
if (empty($_SESSION['user_info']) || empty($_SESSION['user_info']['active'])) {
$response = array("status" => "failed", "login_failed" => 1);
} else {
$response = array("status" => "success", "login_failed" => 0);
}
echo "event: login-verification
";
echo 'data: '.json_encode($response);
echo "
";
flush();
}
while (true) {
send_response();
sleep(2);
}