Hi all!
Recently, I've discovered some strange behaviour regarding variables that are stored in the current session. I'm not a PHP guy in daily life (mostly TypeScript), so maybe I am doing something wrong here... Hopefully, one of you can explain what is happening here.
The thing is: when a user is logging in in my application, I retrieve some user data from the database and store this data in the current session. By doing so, I can just pick some general information such as the current name from the session, instead of going to the database over and over again.
This is the general idea (very simplified):
$userId = Base::instance()->get('POST.id');
$userModel = new UserModel();
$user = $userModel->getById(userId );
if (!$user->dry()) {
// Login logic...
// Setting some commonly used vars
Base::instance()->set('SESSION.firstName', $user->firstName);
...
}
However, after some time, I notice that the session vars are turned out to be empty. So, it seems that something is clearing them. Is this as expected and is my implementation wrong here?
Initially, I though that the garbage collector was removing some stuff here, but I guess that is not what actually happening here; I've changed the following gc_ vars in the application startup script with ini_set to increase the session lifetime tremendously, but that does not help (gc_maxlifetime, gc_probability, gc_divisor).