Save Session Variables to Database on Session Expire
I am wondering if it is po开发者_如何学Gossible to rescue session data into a database or a file when the session expires. For example when I have a object living in my session, will the destructor be called when the session expires?
Basically the question is about how PHP handle sessions when they expire.
Thanks for your help!
It looks like you can use the session_set_save_handler
function to define a callback that gets called whenever the session is destroyed.
As a side note, I would question whether or not it's good design to be saving data when the session times out, rather than just saving it during the session.
To change the max lifetime for a session try this:
ini_set("session.gc_maxlifetime", "18000");
This will set the lifetime to 5 hours. You have to use this in every script that you want to change the default lifetime for.
To get the lifetime of a session:
echo ini_get("session.gc_maxlifetime");
精彩评论