Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 4 session expire too soon

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.

like image 290
Gabriele Castoro Avatar asked Jan 31 '19 12:01

Gabriele Castoro


1 Answers

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
like image 156
Gabriele Castoro Avatar answered Oct 18 '22 01:10

Gabriele Castoro