7

My php session with Symfony 4.0 expire too soon even if I set it up for several days in config/packages/framework.yaml.

framework:

{...}
session:
    handler_id: ~
    cookie_lifetime: 604800
{...}

When the user complete the signin process, he can navigate on the website and, if he return after few minutes, he doesn't need to signin again.

But if he return after 1 or 2 hours (don't know precisely) the session is expired and he must sign in again.

One of the solution that seems worked, was to change what you see above in:

handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/sessions"
cookie_lifetime: 604800    

Unfortunately that solution solved the problem in the dev environment, but crashed the app once that I pulled the code on the server.

Gabriele Castoro
  • 208
  • 1
  • 2
  • 7
  • maybe you have no rigths to change php.ini on you server: https://secure.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime https://symfony.com/doc/current/components/http_foundation/session_configuration.html#session-lifetime – myxaxa Jan 31 '19 at 13:25
  • How can I understand if my Symfony Config file is overriding my php ini file? @myxaxa – Gabriele Castoro Feb 01 '19 at 14:14

1 Answers1

12

Problem solved.

The problem was save_path. Just use the parameters suggested in the official Symfony Documentation. In this way your cookies will be correctly stored.

session:
    handler_id: session.handler.native_file
    save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
    cookie_lifetime: 604800
Gabriele Castoro
  • 208
  • 1
  • 2
  • 7