i am doing one small application , wheich have login functionality,
in the user table am maintaining the AVAILABLE status for the logged USER,
example :
i have three user called foo1,foo2,foo3 ,
When foo1 logged then his AVAILABLE STATUS WILL UPDATE AS 1 IN THE USERTABLE, if he logged out then his AVAILABLE STATUS goes to 0,
like the foo2, and foo3 ,
for this available status flasg , amsimply using the update operation ..no other big functionality ,
Now What i want is,
If somthing happened when user logged in , then i want to make the available status as 0,
Somthing means , I WANT TO CHANGE THE AVAILABLE STATUS TO 0 , WHEN system CRASH OR browser crash
Thanks 开发者_StackOverflow社区Bharanikumar
You can use try-catch blocks on your code/ So - on the main program enter-point you can insert the try block and on the end - catch the exception
try
{
// include main files with functionality
}
catch ( Exception $e )
{
// here you can log the exception text $e->getText()
// take current user ID and set his status
setStatus($_SESSION['user_id']);
}
You need a heartbeat. That would be something (jscript perhaps) running on the client machine that periodically sends a simple message to the server. When the server receives the message, it resets the last time received for that user. A thread in the server runs across the user table on a regular basis and checks the heartbeat timeout. If any user has not had a heartbeat within the timeout period, they get logged out.
Since you can't do much work after the system crashes, it seems that you will have to periodically update the table, and keep track of when the update occurred. And have another process that monitors the age of the last update. If the record has not been updated in a certain amount of time and the user is still active, then the session or system has disconnected for some reason. My suggestion would be to track the last time, not just use a boolean Available_Status field.
I am not sure you will be able to tell if the browser has crashed. You could how-ever perhaps run a php script in the background (batch file calling php) to test if the site was alive, and change the users to 0 if your script stops. But if the script stopped, would you have access to the database/php anyways?
精彩评论