symfony2 会话生命周期 [英] symfony2 session lifetime

查看:45
本文介绍了symfony2 会话生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 symfony2 会话组件时遇到了问题.我通过会话容器将一些数据设置为会话,如下所示:

I had a problem with symfony2 session component. I set some data to session through session container like this:

$sess = $this->get( 'session' );
$sess->set( 'some_key', 'some_value' );

但是过了一小段时间(大约 15-20 分钟)后,会话就丢失了.

But after a little bit of time (about 15-20 minutes) the session got lost.

我可以设置会话生存时间参数吗?对我来说最完美的变体是,如果我可以设置会话直播时间的特定时间......有人可以帮忙吗?

Can I set session life time parameter? The perfect variant for me would be if I can set certain time of session live period...Can anybody please help?

推荐答案

您可以在 framework 部分下的配置文件中设置会话过期时间.我的看起来像这样:

You can set the session expiration time in your config file under the framework section. Mine looks like this:

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

您可以将 framework.session.lifetime 值更改为您想要的任何值,以秒为单位(默认为 3600 或 1 小时).

You can change the framework.session.lifetime value to anything you'd like, in seconds (it defaults to 3600, or 1 hour).

参考此处.

这篇关于symfony2 会话生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆