我遇到了symfony2会话组件的问题.我通过会话容器将一些数据设置为会话,如下所示:
$sess = $this->get( 'session' );
$sess->set( 'some_key', 'some_value' );
Run Code Online (Sandbox Code Playgroud)
但经过一段时间(大约15-20分钟)后,会议就丢失了.
我可以设置会话生存时间参数吗?对我而言,完美的变体就是如果我可以设定一定的会话时间......有人可以帮忙吗?
Pro*_*tic 54
您可以在framework部分下的配置文件中设置会话到期时间.我看起来像这样:
config.yml
framework:
secret: %secret%
charset: UTF-8
error_handler: null
csrf_protection:
enabled: true
router: { resource: "%kernel.root_dir%/config/routing.yml" }
validation: { enabled: true, annotations: true }
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
session:
default_locale: %locale%
cookie_lifetime: 3600 // was "lifetime" but deprecated
auto_start: true
Run Code Online (Sandbox Code Playgroud)
您可以将framework.session.lifetime值更改为您想要的任何值,以秒为单位(默认为3600或1小时).
参考这里.
Tho*_*ett 35
在Symfony 2.3中我认为正确的答案可以在app/config/config.yml中找到:
framework:
session:
cookie_lifetime: 7200
gc_maxlifetime: 3600
Run Code Online (Sandbox Code Playgroud)
每次服务器命中时都会重置GC(垃圾收集),这意味着如果用户处于活动状态,他将有3600继续工作.这cookie_lifetime将强制用户注销其限制.在此示例中,用户将有一个小时处于非活动状态,并将在2小时内强制退出.
为了舒适地工作,您可以在开发环境a中进行设置cookie_lifetime to 0,这意味着cookie将在关闭浏览器时过期。
档案:config_dev.php
framework:
session:
cookie_lifetime: 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49010 次 |
| 最近记录: |