本文介绍了Laravel 4.2会话表未清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Bluehost上托管了一个Laravel 4.2应用程序,并且我试图弄清为什么MySql会话表从未被清除.我曾尝试增加彩票,但仍然没有喜悦.有什么想法吗?

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?

以下是相关的session.php设置:

Here are the relevant session.php settings:

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

推荐答案

在每个请求上,Laravel使用会话lottery值生成一个随机数,该随机数将确定是否将运行会话垃圾回收.它使用的确切代码是:

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];

如果这是真的,则将运行垃圾收集并检查是否有更早的条目,然后lifetime设置.

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

使用默认设置,这意味着mt_rand(1, 100) <= 2必须为true,这将平均每50个请求运行一次垃圾收集器.因此,仅将lottery设置为(20, 100)仍将要求应用程序在触发垃圾收集器之前获得一些请求.

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.

如果要清除表中的旧会话,只需将lottery值设置为(100, 100)(或任意两个相等的值)并刷新应用程序即可.

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.

这篇关于Laravel 4.2会话表未清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 16:35