Calling custom method before session auto destroy
Is there any way to call a custom method before session gets auto/mannual destroyed?
My problem is, I am capturing user logout time in the DB. Its working fine when user gets logout manually (By calling logout method) but I am not able to capture logout time when user's session gets auto destroyed after timeout.
Appreciate suggestions on this.
Yes it is possible. See this website for a in-depth tutorial Using session_set_save_handler() (PHP doc) you can add your own function for the GC (garbage collection) cycle. That way you can tell which sessions are about to be destroyed by that garbage collection cycle, and manually update those records in the database with the current timestamp.
If you then end your function by calling the default GC handler you've basically inserted your own bit of logic in between.
In php you can implement SessionHandlerInterface and use your custom code on destroy() or gc() (see comments), more info here - http://php.net/manual/en/class.sessionhandlerinterface.php
In YII you can setup a custom session handler.