简体   繁体   English

如何在Symfony2中增加会话生存期?

[英]How can I increase session lifetime in Symfony2?

I have set the gc_maxlifetime in my config.yml file to 300. But its not working. 我已将config.yml文件中的gc_maxlifetime设置为300.但它不起作用。 Symfony2 still takes the value set in php.ini Symfony2仍然采用php.ini中设置的值

Symfony version is 2.4.4 Symfony版本是2.4.4

Here is my approach (gotten from Drupal configuration): 这是我的方法(从Drupal配置获得):

  1. set handler to native_file (i'd use PDOSessionHanlder, but seems it's not very stable); 将处理程序设置为native_file (我使用PDOSessionHanlder,但似乎它不是很稳定);
  2. create a seesions directory under app folder; app文件夹下创建一个seesions目录;

config.yml file: config.yml文件:

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

Try setting the cookie_lifetime parameters of the session config key. 尝试设置会话配置密钥的cookie_lifetime参数。

session:
    cookie_lifetime: 300 # override php.ini config

as described here 描述在这里

hope this help 希望这个帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM