Laravel 4.2 Session Table Not Getting Cleaned Up

。_饼干妹妹 提交于 2019-12-25 16:47:05

问题


I have a Laravel 4.2 app hosted on Bluehost and I'm trying figure out why the MySql session table never gets cleaned up. I've tried increasing the lottery but still no joy. Any ideas?

Here are the relevant session.php settings:

'driver' => 'database',
'lifetime' => 180,
'expire_on_close' => true,
'lottery' => array(2, 100)

回答1:


On every request Laravel uses the session lottery value to generate a random number that will determine if it will run the session garbage collection. The exact code it uses is:

mt_rand(1, $config['lottery'][1]) <= $config['lottery'][0];

If this is true garbage collection will run and check for any entries older then the lifetime setting.

With the default settings this means that mt_rand(1, 100) <= 2 must be true, which will run the garbage collector on average every 50 requests. So just setting the lottery to let's say (20, 100) will still require the application to get some requests in before the garbage collector is triggered.

If you want to clear the old sessions from the table just set the lottery value to (100, 100) (or any 2 equal values) and refresh the app.



来源:https://stackoverflow.com/questions/26744921/laravel-4-2-session-table-not-getting-cleaned-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!