Skip to content

Commit

Permalink
Allow only one failed start_session attempt (#73)
Browse files Browse the repository at this point in the history
* Correct typehint, closes #45

* Implement session destruction when failure to start
Closes #66

* Simplify destroying failed session

* Allow only 1 failed start of session

* fix: off by one error - caught by phpstan
  • Loading branch information
g105b authored Feb 2, 2023
1 parent d720a13 commit 954cc13
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function __construct(
);
$sessionName = $config["name"] ?? self::DEFAULT_SESSION_NAME;

// Allow a single failure to start session. If it fails to start,
// destroy the existing session.
$startAttempts = 0;
do {
$success = session_start([
"save_path" => $sessionPath,
Expand All @@ -60,10 +63,11 @@ public function __construct(
]);

if(!$success) {
session_destroy();
@session_destroy();
}
$startAttempts++;
}
while(!$success);
while(!$success && $startAttempts <= 1);

$this->sessionHandler->open($sessionPath, $sessionName);
$this->store = $this->readSessionData();
Expand Down

0 comments on commit 954cc13

Please sign in to comment.