Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session sweeping lottery

Can someone explain what a session sweeping lottery is? I've attached the default session config file for the Laravel framework.

Questions: 1. It says that some session drivers must manually sweep their storage location. Could someone describe this process and why it is necessary? What session drivers require this action? 2. Why is a lottery necessary? If say some form of storage (database) is full, why does it have to be random? Why can't the framework sweep the old sessions when it detects that the driver is full?

/*
|--------------------------------------------------------------------------
| Session Sweeping Lottery
|--------------------------------------------------------------------------
|
| Some session drivers must manually sweep their storage location to get
| rid of old sessions from storage. Here are the chances that it will
| happen on a given request. By default, the odds are 2 out of 100.
|
*/

'lottery' => array(2, 100),
like image 958
Snowball Avatar asked Feb 17 '16 12:02

Snowball


1 Answers

So, a session is a piece of data that is stored on the server for a certain amount of time.

Imagine using a folder with files to store the sessions. There has to be a moment where the old sessions should be cleared. Because there is no way to automaticly check the files every x hours the session files are checked on certain requests.
This setting is the chance this check will happen. In this case 2 out of 100 for every request.

I think the only session driver that currently needs this is the database driver.

If you sweep the storage when it is full, there is a chance that new sessions won't be able to start untill the storage has been sweeped.
If you would sweep the storage on every request, all of your requests would become very slow.

like image 105
Jerodev Avatar answered Oct 03 '22 02:10

Jerodev