-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Add a way to avoid the session be written at each request #9119
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
Conversation
adrienbrault
commented
Sep 24, 2013
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no (maybe the DI config ?) |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | N/A |
License | MIT |
Doc PR | symfony/symfony-docs#3017 |
ping @Drak |
{ | ||
$session = $this->wrappedSessionHandler->read($sessionId); | ||
|
||
$this->readSessions[$sessionId] = $session; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens on session regenerate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that write
wont be able to know if the session has been modified or not and will save it
This PR is an interesting concept - without accepting or rejecting here are some thoughts: The problem is that once a session starts, technically it should always be written after each request because if not, the meta-data would not be updated accurately. That would lead to unpredictable results for code that relies on metadata - like session idle time expiry (which could be really important in secure applications). That is my big objection to the other PRs I've seen that try to limit session writes only if the session attributes/flashes are updated - the session is always updated each session, so it should be written each time. I'm a big fan of feature configurability, and something like this could be useful in some less security critical applications so long as it's not on by default because it would be unsuitable for some applications, e.g. a session idle period could be longer than expected because of update threshold setting. This would have to be well documented. It's certainly the best idea I've seen yet. There are other possibilities too, again using a proxy on the session handler to limit writes under certain conditions. In Zikula we do that for guest sessions (where our userid=0). Remember proxies work in all cases except for native session handlers under PHP 5.3: mostly we use user handlers anyway. Just a point for documentation. |
@@ -222,6 +222,19 @@ private function addSessionSection(ArrayNodeDefinition $rootNode) | |||
->scalarNode('gc_probability')->end() | |||
->scalarNode('gc_maxlifetime')->end() | |||
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end() | |||
->scalarNode('metadata_update_threshold') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be an integerNode ?
@Drak This should only make the session last less time in some cases, but not longer. |
I must say, that I certainly don't oppose this PR. I've been quite against the other proposals in this area so far, but this seems quite reasonable. It's clean, optional, and it will be well documented. I need more time to review the code and digest it, but in principal it seems ok to me. |
@fabpot - I spent a long while thinking about this PR and I do think it's really good. It would make a nice addition. It's completely BC, nothing breaks as far as I can see. |
@adrienbrault Can you work on adding some docs for it? |
Sure. Btw, do you have another name idea for the |
Doc PR: symfony/symfony-docs#3017 |
@adrienbrault docs look good to me except that you forgot to mention @Drak warning ("Remember proxies work in all cases except for native session handlers under PHP 5.3: mostly we use user handlers anyway.") @Drak just that to double-check your above comment:
|
@fabpot Regarding the proxy mechanism and PHP 5.3 maybe I will point this out in the Sessions docs more clearly. I added proxy to mimic the PHP 5.4 feature of the I mean there are other uses of the proxy to reduce session writes, for example in Zikula the proxy is useraware and does not persist unauthenticated users. You could also make it user-agent aware and not persist sessions for google-bot et al. This is the best place because code still relies on sessions to be started. Preventing the persist is the best strategy in those cases. Regarding the meta-data, @adrienbrault answered my questions, so yes, I do not see any drawbacks. This is a really nice use of the proxy mechanism and I don't see any drawbacks. I was just being cautious. I still believe it must be well documented because it does alter expected behaviour, but that's not a criticism, just a good for the developer to know what the codes effects are. Basically this PR will cause the session to be updated if the content has changed, but not if there only a metadata change AND a certain time period has elapsed. It's brilliant. |
@adrienbrault how about |
The WriteCheckSessionHandler has nothing to do with frequency. Hmm What about |
@adrienbrault That's misleading IMO because what you are doing is changing the granularity at which the metadata is updated and thus changing the session data. It's not just a matter of whether other session data has been modified, it's all about the timing and frequency - so something that reflects that would be better. |
@Drak but there are 2 different settings that can be used in different On Saturday, September 28, 2013, Drak wrote:
|
@adrienbrault as I understand it, one enables the feature, the other configures the threshold. So the enable toggle should be named |
@Drak I created 2 different settings because the Maybe we should only have 1 setting in the FrameworkBundle configuration ? |
@adrienbrault sure, but in reality |
@adrienbrault Sorry I didn't answer the last part. I think it would be better to have one setting, which when false or 0 does nothing, and if you set a value, it sets up the proxy and also sets the threshold in the metadata object. |
@Drak Thanks, will do that |
Updated along with the documentation PR |
->integerNode('metadata_update_threshold') | ||
->defaultValue('0') | ||
->info( | ||
'time to wait between 2 session metadata updates'.PHP_EOL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer just one sentence without a line break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Apparently, it breaks a test: |
Only failing on PHP 5.3 http://php.net/manual/en/function.session-status.php
I don't think this is related to this PR |
@adrienbrault that's not related to this PR for sure. It comes from |
@@ -222,6 +222,10 @@ private function addSessionSection(ArrayNodeDefinition $rootNode) | |||
->scalarNode('gc_probability')->end() | |||
->scalarNode('gc_maxlifetime')->end() | |||
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end() | |||
->integerNode('metadata_update_threshold') | |||
->defaultValue('0') | |||
->info('time to wait between 2 session metadata updates, it will also prevent the session handler to write if the session has not changed') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should mention what the units are 1 seconds, millisecond etc?
👍 |