ghedipunk / PHP-Websockets

A Websockets server written in PHP.
BSD 3-Clause "New" or "Revised" License
917 stars 375 forks source link

Disconnect idle clients #103

Open rts-ssoundar619 opened 7 years ago

rts-ssoundar619 commented 7 years ago

I want to disconnect idle clients from the server. I am using android application as a client and sending data's from the server to client. If internet disconnects on the mobile the client will not send close to server. How can I find out the idle clients and disconnect it.

petrospap commented 6 years ago

you can try with javascript, something like this

var useridtest = 5;
function idleUser() {
var t;
window.onload = rst;
window.onmousemove = rst;
window.onmousedown = rst;
window.onclick = rst;
window.onscroll = rst;
window.onkeypress = rst;

function action() {
// window.location.href = 'logout.php';
alert('idle use rid test ='+useridtest);
}

function rst() {
clearTimeout(t);
t = setTimeout(action, 10000);  // time is in milliseconds 300000 = 5 min
}
}
idleUser();