-
Notifications
You must be signed in to change notification settings - Fork 61
Fix #104: php 7.2 handle ini_set() when session already started #107
Conversation
src/Config/SessionConfig.php
Outdated
@@ -133,7 +133,18 @@ public function setStorageOption($storageName, $storageValue) | |||
break; | |||
} | |||
|
|||
$sessionAlreadyStarted = false; |
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'd rename this to $sessionRequiresRestart
, as it better conveys what needs to happen. This is particularly important when you come to line 144, as calling session_start()
because $sessionAlreadyStarted
seems like a mistake when just looking at the verbiage.
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've updated variable to sessionRequiresRestart
src/Config/SessionConfig.php
Outdated
$sessionAlreadyStarted = false; | ||
if (session_status() == PHP_SESSION_ACTIVE) { | ||
$sessionAlreadyStarted = true; | ||
session_write_close(); |
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.
Honestly, this seems really problematic, considering your original use case as demonstrated in #104. It means that you are starting, stopping, and restarting your session on every request, resulting in I/O even if no data is ever written or accessed. This may not seem like a big deal, but it can lead to longer response times (due to I/O of writing the session), and potential concurrency issues.
Wouldn't it be more performant and less prone to error to do as I suggested in that issue and inject the fully configured session manager into your container during instantiation? Have you tried the solution I posted on that issue?
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.
Yes, I tried your solution, but that still got issue, for example, on call sessionmanager ->rememberMe()
after login success that requires changes cookie lifetime, while session already active.
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.
also when calling sessionmanager->forgetMe()
as it set cookie_lifetime to 0, while session already started
…ave $sessionRequiresRestart setted value to true when session need to be restarted
…id race condition
@weierophinney I've updated code to check |
@samsonasik One other thing that could make this better, particularly for the use case you presented in the original issue: check to see that the storage option provided differs from the one already set. If it isn't different, the method can bail early, without attempting the |
@weierophinney do you mean that we need to add : |
Yes; it would bail early, before any attempts to determine if the session needs to be restarted, or setting the INI value, if the values are the same. |
@weierophinney I've updated to have |
Thanks, @samsonasik! |
Provide a narrative description of what you are trying to accomplish:
We can't call
ini_set()
when session already startedWhen it called, it got error : "ini_set(): A session is active. You cannot change the session module's ini settings at this time"
It call
session_write_close()
first, then start the session againmaster
branch, and submit against that branch.CHANGELOG.md
entry for the fix.