Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpFoundation] Allow changing the redis session TTL at runtime#44368

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Seldaek wants to merge2 commits intosymfony:6.1fromSeldaek:patch-14

Conversation

@Seldaek
Copy link
Member

QA
Branch?6.1
Bug fix?no
New feature?no
Deprecations?no
Tickets
LicenseMIT
Doc PR

A tiny setter addition, because I do have a use case where I need to change the session TTL at runtime only for some users, and right now I need ReflectionProperty which isn't great.

@carsonbotcarsonbot added this to the6.1 milestoneNov 30, 2021
@SeldaekSeldaek changed the titleAllow changing the redis session TTL at runtime[HttpFoundation] Allow changing the redis session TTL at runtimeNov 30, 2021
@ro0NL
Copy link
Contributor

Would allowing a callback for $options['ttl'] make sense?

@Seldaek
Copy link
MemberAuthor

I guess, but it makes it all more complex and it would only work for php container configs. Plus for my use case it'd really complicate things I think, compared to injecting the Redis handler in another service and modifying it at runtime.

@nicolas-grekas
Copy link
Member

Can you share a bit more about your use case?
We try to avoid making services mutable as much as possible, so I'm looking for alternatives...

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedDec 2, 2021
edited
Loading

Actually, you can already change the ttl at runtime: set the ttl to null when creating the object, and use ini_set when you need a dynamic ttl!

@Seldaek
Copy link
MemberAuthor

Yeah I tried that but it doesn't work because ini_set prevents you from changing session.gc_maxlifetime once a session is started.

The use case is we have some users which require a longer session lifetime, so we have a request listener changing the session TTL for them, making sure that the SETEX at the session write is done with the correct TTL. We do need to know the user though so we kinda have to do that after the session is started.

@ro0NL
Copy link
Contributor

What about an immutablewithOptions, to ease decoration per TTL.

@Seldaek
Copy link
MemberAuthor

I think I'd rather keep my ReflectionProperty hack tbh 😅

@nicolas-grekas
Copy link
Member

It would make more sense to add this method to the Session instance to me.

ro0NL reacted with rocket emoji

@Seldaek
Copy link
MemberAuthor

@nicolas-grekas I am not sure I understand how that would work. Session->setTtl you mean, then how does that call it on the storage? Would need to add setTtl to SessionStorageInterface, and then one would still need a new interface for the handlers themselves to implement as SessionHandlerInterface is native.

Sounds like a lot of mess just for this tiny use case. I could add it as well to MemcachedSessionHandler though for completeness, but other handlers really have no way of changing a TTL at runtime anyway.

@fabpot
Copy link
Member

What's the status here?@nicolas-grekas?

@Seldaek
Copy link
MemberAuthor

Closing in favor of#45873

@SeldaekSeldaek deleted the patch-14 branchMarch 29, 2022 10:06
fabpot added a commit that referenced this pull requestMar 30, 2022
…g a remote storage (nicolas-grekas)This PR was merged into the 6.1 branch.Discussion----------[HttpFoundation] Allow dynamic session "ttl" when using a remote storage| Q             | A| ------------- | ---| Branch?       | 6.1| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       |Fix#44368| License       | MIT| Doc PR        | -This is my proposal instead of#44368. My goal here it to *not* make the session handler mutable.Instead, I propose to allow defining the "ttl" option as a closure.Here is how this would work in practice:```yamlservices:  my.session.handler:    parent: session.abstract_handler    arguments:      index_0: 'redis://localhost'      index_1: {ttl: !closure ['@my.ttl.handler']}```Where `my.ttl.handler` would be an invokable that returns the ttl for the current user (based on the session object from the request stack, or from the token storage I suppose)./cc@Seldaek I'd be happy to have your thoughts here (and also your help for tests/doc ideally 👼)Commits-------51fc454 [HttpFoundation] Allow dynamic session "ttl" when using a remote storage
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

5 participants

@Seldaek@ro0NL@nicolas-grekas@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp