8000 [WIP][HttpFoundation][Sessions] NativeFileSession won't override the php.ini settings anymore by dlsniper · Pull Request #5266 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP][HttpFoundation][Sessions] NativeFileSession won't override the php.ini settings anymore #5266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

dlsniper
Copy link
Contributor

Bug fix: yes - but in the 2.1 branch
Feature addition: no
Backwards compatibility break: not sure
Symfony2 tests pass: Build Status
Fixes the following tickets: ~
Todo: ~
License of the code: MIT
Documentation PR: ~

Today I've noticed that the sessions are stored in files even if the configuration of the PHP server was to use the memcached driver to do so.
After a bit of digging I've noticed that the native storage solution Symfony2.1 comes with will override the server settings in the PHP.ini which is very bad as this is not the expected default behavior.
I think this should be solved before releasing 2.1 as the changes for the session subsystem are already major.
One other thing to add to this would be to force the sessions to be stored in files regardless of the settings in php.ini but for that I think we need to use a configuration option. If you think that it would be better to solve the problem that way then I'll gladly do it.

cc @fabpot @Drak

@travisbot
Copy link

This pull request passes (merged e01a3fd into 826f512).

@@ -33,6 +33,13 @@ class NativeFileSessionHandler extends NativeSessionHandler
*/
public function __construct($savePath = null)
{
// We don't want to override the server settings in case the server is configured to handle sessions
// in something else that files. This makes it easy to configure servers to have sessions stored in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo => than

Copy link
Contributor Author

Choo 8000 se a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed that.

@ghost
Copy link
ghost commented Aug 15, 2012

But the point here is if you are using NativeSessionFileHandler then you are commanding Symfony to use native files, so this PR would completely break when you want to command use of native file...

This is actually why there were other native drivers (sadly those were removed).

If you want to preserve the actual save_handler as set in php.ini, then you should pass null to the handler of the NativeSessionStorage. I would strongly suggest however that for a robust application, you should not be relying on PHP ini globals but rather setting them explicitly.

@dlsniper
Copy link
Contributor Author

@Drak thanks for your reply. To better explain the situation:

The application I've developed has been on master ever since February with somewhat regular updates. I haven't done any other profiling and benchmarks so far because we've focused on the development of other features. I know about the removal of the other NativeSessionsStorage drivers, which is a pity, but I've understood the reasons for removal.

But now the problem we're faced is like this: we want to use memcached as session server. If we don't write any code for it then it should be the fastest/reliable way to implement it as we control the web servers. If we need to write code for this then it means we need to test it and so on.

Out of the box, we've expected that native NativeFileSessionHandler would just mean that we can implement whatever we want in php.ini and it would just use that. We plan to study Redis for example at some point and switching the drivers would just mean more tests. So this kinda came as a surprise when we've seen that files are being written instead of using what we've did in php.ini.

Maybe a solution would be to implement a NativePHPSettingsHandler and ship it with Symfony2 but imho if you look at the configuration of Symfony2 Standard, you wouldn't expect that the sessions are not obeying the rules of php.ini. Or maybe we can implement an option called obey_ini_settings or something that can be used instead to signal what Symfony should do.

Yet another thing that we might just as well change would be to change the sessions storage path to have it under app/sessions/[SF2_ENV]/ as it seems there's a lot of people clearing their cache and just forgetting/not knowing that the sessions folder is in their cache folder.

What do you think about these?

@dlsniper
Copy link
Contributor Author

Moved over #5267
Sorry for the inconvenience.

@dlsniper dlsniper closed this Aug 15, 2012
@ghost
Copy link
ghost commented Aug 15, 2012

@dlsniper

Out of the box, we've expected that native NativeFileSessionHandler would just mean that we can implement whatever we want in php.ini and it would just use that

No, it is as the name says - native file session handler :-)

Maybe a solution would be to implement a NativePHPSettingsHandler and ship it with Symfony2 but imho if you look at the configuration of Symfony2 Standard, you wouldn't expect that the sessions are not obeying the rules of php.ini.

As I said before if you want to leave the save handlers as specified in php.ini (which is a mistake imo), then simply pass null to the NativeSessionStorage constructor for the handler arg.

As a matter of principal, an application's configuration be explicit and not make assumptions about the environment it's deployed in. You might have an exception for this, but as a general rule, the application should behave the same way on server 1 or server 2 because it makes the application robust and saves some poor admin time scratching their head as to why server 1 works, and server 2's deployment doesn't.

But now the problem we're faced is like this: we want to use memcached as session server. If we don't write any code for it then it should be the fastest/reliable way to implement it as we control the web servers. If we need to write code for this then it means we need to test it and so on.

This is why we had the Native* drivers - and this is exactly why I was against them being removed because it's now more annoying to use them. We were told instead, that if someone wants to implement native storage handlers they should directly specify ini_set('save_handler', 'memcache') or whatever which is suddenly outside of the whole paradigm we expect in Symfony.

Yet another thing that we might just as well change would be to change the sessions storage path to have it under app/sessions/[SF2_ENV]/ as it seems there's a lot of people clearing their cache and just forgetting/not knowing that the sessions folder is in their cache folder.

This is already configurable, the default folder is sensible for most purposes. Especially when testing or re-deploying clearing out sessions may make very good sense.

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

Successfully merging this pull request may close these issues.

3 participants
0