简体   繁体   English

Laravel 会话文件未从框架/会话文件夹中清除

[英]Laravel Session files not cleaning from the framework/sessions folder

I am on a shared host (OVH pro) using Laravel 5.2 on production (PHP 7.0.5).我在共享主机(OVH pro)上使用 Laravel 5.2 生产(PHP 7.0.5)。

I am using the file session driver , and everything was working fine on my previous host (with the same app), but since I moved to OVH, the session files keep being created and are never deleted by the PHP garbage collection.我正在使用文件会话驱动程序,并且在我以前的主机上一切正常(使用相同的应用程序),但是自从我移到 OVH 后,会话文件不断被创建并且永远不会被 PHP 垃圾收集删除。 I have to manually erase the files ( over 5000 files are created per day ).我必须手动擦除文件(每天创建 5000 多个文件)。

My config/session.php file is set up correctly:我的config/session.php文件设置正确:

'driver' => 'file',
'lifetime' => 120,
'lottery' => [2, 100],

And my folders storage , storage/framework , storage/framework/sessions are all set with a 0755 permission.我的文件夹storagestorage/frameworkstorage/framework/sessions都设置了 0755 权限。

I also override the php.ini by placing those 2 lines at the top of config/session.php我还通过将这两行放在config/session.php的顶部来覆盖php.ini

ini_set('session.gc_probability', '5');
ini_set('session.gc_divisor', '100');

It seems to be working fine from what phpinfo() returns:phpinfo()返回的内容来看,它似乎工作正常: PHP 会话信息

I contacted my host, but they told me it must have to do with my Laravel app, and they can't help.我联系了我的主人,但他们告诉我这一定与我的 Laravel 应用程序有关,他们无能为力。

Edit: My sessions work fine, I mean that there's only one file created per visitor.编辑:我的会话工作正常,我的意思是每个访问者只创建一个文件。 The problem is only the fact that the session files are not getting cleaned up, even with a 777 permission.问题只是会话文件没有得到清理,即使有 777 权限。


Even when I put the Laravel session lottery to 100/100, the files are still not getting deleted:即使我将 Laravel 会话抽签设置为 100/100,文件仍然没有被删除:

    /*
    |--------------------------------------------------------------------------
    | 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' => [100, 100],

EDIT: OVH hosting specifics: I use multisites on OVH, and the folders containing each site are placed at the route of my OVH host, and not in the default www folder.编辑: OVH 托管细节:我在 OVH 上使用多站点,并且包含每个站点的文件夹放置在我的 OVH 主机的路径上,而不是在默认的www文件夹中。

I did that for security reasons, because the www folder is publicly available through mynickname.cluster005.ovh.net and I dont want any of my sites to be publicly available from出于安全原因,我这样做了,因为www文件夹可通过mynickname.cluster005.ovh.net公开访问,我不希望我的任何站点从

mynickname.cluster005.ovh.net/site1

mynickname.cluster005.ovh.net/site2 ... mynickname.cluster005.ovh.net/site2 ...

( www\\site1 , www\\site2 ...). www\\site1www\\site2 ...)。

So I was thinking that maybe only the files located inside www folder are writable, and maybe not the one outside (at the root)?所以我在想,也许只有位于www文件夹内的文件是可写的,而可能不是外面的(在根目录下)? That would explain while my files are not being deleted.这将解释我的文件没有被删除。 I'll make a test tonight to see if the files are being deleted when placed in www\\site1\\storage\\sessions .我今晚会做一个测试,看看文件放在www\\site1\\storage\\sessions时是否被删除。

There some step that you can find what's problem is first有一些步骤可以让您首先找到问题所在

  1. Make sure session ID is fixed in every page (echo session id)确保每个页面中的会话 ID 都是固定的(回显会话 ID)

if session id was changed every page , you need to check your session config domain setting is correct.如果每个页面都更改了会话 ID,则需要检查会话配置域设置是否正确。

if session id didn't change maybe you need change storage folder premision to 777.如果会话 id 没有改变,也许你需要将存储文件夹前提更改为 777。

I hope that can help you.我希望这可以帮助你。

If you are using haproxy , consider this answer:如果您使用haproxy ,请考虑以下答案:

Session files may be created by the haproxy's http health checks .会话文件可能由haproxy's http health checks

  1. Check your web access logs to fixed interval access.检查您的网络访问日志以固定时间间隔访问。

111.11.111.1 - - [28/Jul/2016:10:40:30 -0400] 200 "GET / HTTP/1.0" 4 "-" "-" "-" 111.11.111.1 - - [28/Jul/2016:10:40:30 -0400] 200 "GET / HTTP/1.0" 4 "-" "-" "-"

111.11.111.1 - - [28/Jul/2016:10:40:32 -0400] 200 "GET / HTTP/1.0" 4 "-" "-" "-" 111.11.111.1 - - [28/Jul/2016:10:40:32 -0400] 200 "GET / HTTP/1.0" 4 "-" "-" "-"

111.11.111.1 - - [28/Jul/2016:10:40:34 -0400] 200 "GET / HTTP/1.0" 4 "-" "-" "-" 111.11.111.1 - - [28/Jul/2016:10:40:34 -0400] 200 "GET / HTTP/1.0" 4 "-" "-" "-"

  1. Update option httpchk GET / to point to some routes that you could set the session driver to be array on your haproxy.cfg .更新option httpchk GET /指向一些routes ,你可以设置会话司机是array上的haproxy.cfg

  2. add the Config::set('session.driver', 'array');添加Config::set('session.driver', 'array'); line to disable creation of session files.行以禁用会话文件的创建。


Reference:参考:

转到config/session并设置'lifetime' => 120 ,或者一个不要太大的数字,这是会话持续的时间(以分钟为单位)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM