Symfony World blog is not maintained anymore. Check new sys.exit() programming blog.

session timeout in symfony 1.3, 1.4

Scene from "The Shining" by Stanley Kubrick (1980)

One of the main features to configure while developing a website that has access for users (in frontend, backend or both) is to set the session timeout. Its value defines time (measured in seconds) after which user session data will become out of date, if that user has performed no activity. For example, the default session expire time in symfony is 1800, which is 30 minutes (60*30), if a user is logged in and he won't do anything for at least 1800 seconds, he'll be automatically logged out.


solution

There are several blog posts in the internet describing where to change this value, but they refer only to symfony 1.0 (which is really old... and solutions described there do not apply to sf 1.3/1.4). So, the file is apps/APP_NAME/config/factories.yml. You need to add the following lines:

all:
  user:
    class: myUser
    param:
      timeout: 7200

where 7200 can be replaced with whatever unsigned integer value you want. Take a look at the main factories configuration file in symfony core: lib/vendor/symfony/lib/config/config/factories.yml. You'll find the default/user section there which holds all interesting stuff.

15 comments:

  1. nice and helpful

    ReplyDelete
  2. Thanks. Simple to the point and effective.

    ReplyDelete
  3. Well,

    you can also use :

    all:
    user:
    param:
    timeout: false

    But be careful, it apparently doesn't work in sf1.0.

    ReplyDelete
  4. Thanking you very much.

    ReplyDelete
  5. This symfony factories.yml configuration reference explains everything about user configuration:
    http://www.symfonyreference.com/factories-yml

    ReplyDelete
  6. Another Thank you !!!

    ReplyDelete
  7. If it's not working, you have to check your PHP server configuration which also has to be set properly. Display phpinfo() and look at session.gc_maxlifetime

    ReplyDelete
  8. This could help also if you are having issues with the cookie logged time, in config\app.yml:
    # default values
    #all:

    all:
    a:
    # If true, there will be a language switcher next to the login/logout button
    i18n_switch: true
    i18n_languages: [es, en]

    #http://www.symfony-project.org/plugins/sfGuardPlugin
    #http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin
    sf_guard_plugin:
    remember_cookie_name: dbvui_cookie
    remember_key_expiration_age: 2592000 # 30 days in seconds

    ReplyDelete
  9. Yes it help me!

    ReplyDelete
  10. it works for me. really thanks!!

    ReplyDelete