Issue with session.handler.native_file session han

2019-07-11 12:15发布

问题:

I'm facing a really weird issue with an application i'm working on based on symfony2 (2.5).

Long story short: in the config.yml file i have this:

framework:
  ...
  session:
      name: "a_given_name"

      # THE FOLLOWING LINE CAUSES THE PROBLEM
      handler_id: session.handler.native_file

      save_path: "%kernel.root_dir%/sessions"
      cookie_lifetime: 2629744 #1 month
      gc_maxlifetime: 2629744 #1 month
  ...

And session does not work! I checked everything, the system create the files but those files are always empty.

Changing the entry realated to "handler_id" in config.yml to: "~" everything works fine.

framework:
  ...
  session:
      # CHANGING TO THE FOLLOWING -> IT WORKS
      handler_id: ~
  ...

But, as stated in the docs, the "session.handler.native_file" is the default hanlder... so it should work anyway...

Any help about it? Thanks a lot...

回答1:

I faced the same issue when running Vagrant machine.

I recommend to move sessions out of the synced folders (default /var/www/html) to new location, e.g. /home/symfony/sessions

framework:
    session:
        handler_id:  session.handler.native_file
        save_path:   "/home/symfony/sessions/%kernel.environment%"

Also, helpful article: https://coderwall.com/p/h3i5mw/symfony-session-problems-with-vagrant