How can I increase session lifetime in Symfony2?

2.2k views Asked by At

I have set the gc_maxlifetime in my config.yml file to 300. But its not working. Symfony2 still takes the value set in php.ini

Symfony version is 2.4.4

2

There are 2 answers

2
Matteo On

Try setting the cookie_lifetime parameters of the session config key.

session:
    cookie_lifetime: 300 # override php.ini config

as described here

hope this help

0
xurshid29 On

Here is my approach (gotten from Drupal configuration):

  1. set handler to native_file (i'd use PDOSessionHanlder, but seems it's not very stable);
  2. create a seesions directory under app folder;

config.yml file:

session:
    handler_id: session.handler.native_file
    cookie_domain: %cookie_domain%
    name: SFSESSID
    cookie_lifetime: 2000000 # change this if you want
    save_path: "%kernel.root_dir%/sessions"
    gc_divisor: 100
    gc_maxlifetime: 200000 # change this if you want
    gc_probability: 1