Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
701 views
in Technique[技术] by (71.8m points)

symfony - symfony2 session lifetime

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' );

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

Reference here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...