8000 Added config to force Symfony use native session handler by default by pulzarraider · Pull Request #606 · symfony/symfony-standard · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Added config to force Symfony use native session handler by default #606

Closed
wants to merge 1 commit into from

Conversation

pulzarraider
Copy link
Contributor

As far as I know Symfony is using NativeFileSessionHandler to save session data to file. This breaks server configuration, because if php is configured to use Memcache or Redis session handler, symfony stores session data to file in app/cache directory and ignores default php session settings.

Correct me if I am wrong, but Symfony should use native session handler that is configured in php ini settings by default (to create less WTFs).

@bamarni
Copy link
Contributor
bamarni commented Nov 13, 2013

It is expected, Symfony recommends to set the session handler explicitly in its framework bundle configuration instead of relying on ini settings. This makes sure the application behaves the same no matter on which environment it is deployed to.

@fabpot
Copy link
Member
fabpot commented Nov 14, 2013

@bamarni Actually, that's the contrary ;)

I tend to agree with @pulzarraider here.

What do you think @Drak?

@ghost
Copy link
ghost commented Nov 14, 2013

Looking at this the problem is because there is no explicit handler_id set, it can lead to confusion. Whether it is set to NativeFileSessionHanaer or null (in order to use the PHP default) is a matter of taste. I would probably have added the nativefile session hander service to the config line. The advantage is that you are not relying on php.ini values. This makes your application less portable because now you have to be concerned more about the environment as having the hander set explicitly show you can change the values and have a portable application across servers.

But either way, a value should be set explicitly for handler_id (null or otherwise) and documented so it's clear. If you chose ~ I would add a comment

handler_id: ~ # null for defaults set in php.ini 

I personally would have it as

handler_id: session.handler.native_file

since it's not good to rely on global set default, that leads to more wtfs than anything else.

But anyway +1 for having something set explicitly.

@pulzarraider
Copy link
Contributor Author

@Drak @fabpot @bamarni Thanks for your opinions

I have added comment to make the configuration more clear.

My opinion is that application should use default session handler set in php.ini. Session handler from php.ini is
in many companies tunned to the maximum to bring more performance and make sessions available accross multiple servers.

fabpot added a commit that referenced this pull request Nov 24, 2013
… by default (pulzarraider)

This PR was submitted for the master branch but it was merged into the 2.4 branch instead (closes #606).

Discussion
----------

Added config to force Symfony use native session handler by default

As far as I know Symfony is using NativeFileSessionHandler to save session data to file. This breaks server configuration, because if php is configured to use Memcache or Redis session handler, symfony stores session data to file in app/cache directory and ignores default php session settings.

Correct me if I am wrong, but Symfony should use native session handler that is configured in php ini settings by default (to create less WTFs).

Commits
-------

89f82c8 Added config to force Symfony to use native session handler by default
@fabpot fabpot closed this Nov 24, 2013
@bamarni
Copy link
Contributor
bamarni commented Nov 26, 2013

Is symfony cookbook about symfony/symfony or the standard edition? If it's the latter, the following cookbook entry will be obsolete as of 2.4 : http://symfony.com/doc/current/cookbook/session/sessions_directory.html

@bamarni
Copy link
Contributor
bamarni commented Nov 28, 2013

@fabpot : any thought on this? Can it either be backported to 2.3 or postponed to 3.0 so that there is a consistent documentation about it across all ~2.3 versions?

@ghost
Copy link
ghost commented Dec 4, 2013

@fabpot there is now an unfortunate side-effect in that clearing the cache will no longer clear out the session which may be stored in a variety of locations.

Upon re-reading the original text of the ticket, it's wrong to say it "breaks" anything when you need to configure the save_path correctly for the different drivers. That is a bug in the configuration default handling which defaults to a file path if they key is not defined in the config.yml. Of course it's not aware of different default values depending on the storage driver.

What should have happened was to add a key to the config.yml for save_path so it becomes clear there are other values to configure. In fact, for a number of these drivers there are other keys that may need to be configured.

Either that or some kind of intelligent hander_id aware configuration (which is probably difficult to do).

@ghost
Copy link
ghost commented Dec 4, 2013

Something like this

    session:
        handler_id: ~
        #save_path: %kernel.cache_dir%/sessions

making it clear there is more to configure if you change the handler.

The patch that was applied here doesn't actually solve the core issue of someone changing the handler_id: to something else and not configuring the other required args.

The knock-on effect now is that file based sessions are not cleared when you clear the cache dir and are in fact "somewhere else". It's more messy rather than clearer.

I get that one may be deploying a single app on a dedicated server/vm instance and and thus using global php settings can be ok, but it is still a bad idea to rely on as I have discussed before and increases the chances of wtf moments because configuration is no longer self contained, but spread over several places outside the application.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0