I am managing a PHP + APACHE + CENTOS Linux combination.
I've implemented a login &lifier logout online.
My real question is, how do i know once the php session has timed-out (User has closed his browser without logging-out)?
This is because, I would like carry out some clean-ups and/or database updates (calling another PHP) once the user has been doing the following: (1) Drenched-OUT or (2) TIMED-OUT
My prediction is the fact that I would need to take advantage of Apache/Linux, right?
Rather than discovering once the php session occasions out, you can produce a script which will run at some semi regular interval (every a few minutes say, utilizing a crontab job probably) which will log out/perform the cleaning up for anybody who has not been mixed up in last hour (or whatever your timeout value is) instantly. Just give a 'lastseen' for your user table.
You might keep session id inside a database having a time stamp, increase time stamp every time the consumer demands a web page.
Then set a cron that appears at each "active" session, computes the lack of exercise some time and updates the session to "dead" (that might be completed with just one SQL statment that runs periodically).
Also, modify your logout to update the session table and hang the session to "dead".
Anyway, I do not think you will find different ways to get this done (using the "standard" PHP functions), but let's wait and watch the other people say.
I'd exactly the same problem, though with Lighty+PHP+Ubuntu. I believe the issue is, that php does only react on-page-demands, so there's absolutely no way to obtain PHP raise a celebration on timeout.
You are able to override the session-store-functions in PHP but that will not assist you to either.
You can keep duration of last event within the session though, with every session began cleanup old periods which have encounter timeouts. Not really a very clean way, however the only working way I discovered.
Monitoring periods inside a database
Should you keep your particulars of the periods inside a database table and log any action it is simple to determine which periods happen to be inactive for any specific period of time.
Adding cleanup functionality to user actions will decelerate your site unnecessarily. A person should not need to watch for such actions to occur prior to getting an answer in the server.
Rather, you could include those things to become carried out to some queue table, then make use of a CRON job to periodically look into the queue table to determine what must be done. The CRON syntax shows up here.