问题描述
我在生产环境(PHP 7.0.5)上使用Laravel 5.2在共享主机(OVH pro)上.
I am on a shared host (OVH pro) using Laravel 5.2 on production (PHP 7.0.5).
我正在使用文件会话驱动程序,并且在以前的主机(使用相同的应用程序)上一切正常,但是由于我移至OVH,因此会话文件一直在创建,并且从未被PHP垃圾回收删除.我必须手动删除文件(每天创建超过5000个文件).
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.I have to manually erase the files (over 5000 files are created per day).
我的config/session.php
文件已正确设置:
'driver' => 'file',
'lifetime' => 120,
'lottery' => [2, 100],
我的文件夹storage
,storage/framework
,storage/framework/sessions
都设置了0755权限.
And my folders storage
, storage/framework
, storage/framework/sessions
are all set with a 0755 permission.
我还通过将这两行放在config/session.php
I also override the php.ini by placing those 2 lines at the top of config/session.php
ini_set('session.gc_probability', '5');
ini_set('session.gc_divisor', '100');
从phpinfo()
返回的内容来看,它似乎运行良好:
It seems to be working fine from what phpinfo()
returns:
我联系了我的房东,但他们告诉我这一定与我的Laravel应用有关,他们无济于事.
我的会话工作正常,我的意思是每个访问者只能创建一个文件.问题仅在于即使拥有777权限也无法清除会话文件.
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.
即使我将Laravel会话彩票设置为100/100,文件仍然没有被删除:
Even when I put the Laravel session lottery to 100/100, the files are still not getting deleted:
/*
|--------------------------------------------------------------------------
| 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],
编辑:OVH托管详细信息:我在OVH上使用多站点,并且包含每个站点的文件夹都放在我的OVH主机的路由上,而不是在默认的www
文件夹中.
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.
出于安全考虑,我这样做是因为www
文件夹可通过mynickname.cluster005.ovh.net
公开使用,而且我不希望我的任何网站都可通过
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
mynickname.cluster005.ovh.net/site1
mynickname.cluster005.ovh.net/site2
...
(www\site1
,www\site2
...).
所以我在想,也许只有位于www
文件夹内的文件是可写的,也许不是外部的(在根目录下)是可写的?这将解释为什么我的文件没有被删除.今晚我将进行测试,查看放置在www\site1\storage\sessions
中的文件是否被删除.
So I was thinking that maybe only the files located inside www
folder are writable, and maybe not the one outside (at the root)? 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
.
推荐答案
转到config/session
并设置'lifetime' => 120
或一个不太大的数字,这是会话持续几分钟的时间
Go to config/session
and set 'lifetime' => 120
, or a number not too large, this is how long a session lasts in minutes
这篇关于Laravel会话文件无法从framework/sessions文件夹中清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!