Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit b5acadc

Browse files
committed
Merge branch 'hotfix/107'
Close #107 Fixes #104
2 parents 2b57159 + 29cd657 commit b5acadc

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25-
- Nothing.
25+
- [#107](https://github.com/zendframework/zend-session/pull/107) fixes an error
26+
raised by `ini_set()` within `SessionConfig::setStorageOption()` that occurs
27+
for certain INI values that cannot be set if the session is active. When this
28+
situation occurs, the class performs a `session_write_close()`, sets the new
29+
INI value, and then restarts the session. As such, we recommend that you
30+
either set production INI values in your production `php.ini`, and/or always
31+
pass your fully configured session manager to container instances you create.
2632

2733
## 2.8.3 - 2017-12-01
2834

src/Config/SessionConfig.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,24 @@ public function setStorageOption($storageName, $storageValue)
133133
break;
134134
}
135135

136-
$result = ini_set($key, (string) $storageValue);
136+
$iniGet = ini_get($key);
137+
$storageValue = (string) $storageValue;
138+
if (false !== $iniGet && (string) $iniGet === $storageValue) {
139+
return $this;
140+
}
141+
142+
$sessionRequiresRestart = false;
143+
if (session_status() == PHP_SESSION_ACTIVE) {
144+
session_write_close();
145+
$sessionRequiresRestart = true;
146+
}
147+
148+
$result = ini_set($key, $storageValue);
149+
150+
if ($sessionRequiresRestart) {
151+
session_start();
152+
}
153+
137154
if (false === $result) {
138155
throw new Exception\InvalidArgumentException(
139156
"'{$key}' is not a valid sessions-related ini setting."

test/Config/SessionConfigTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ public function testNameAltersIniSetting()
9696
$this->assertEquals('FOOBAR', ini_get('session.name'));
9797
}
9898

99+
public function testNameAltersIniSettingAfterSessionStart()
100+
{
101+
session_start();
102+
103+
$this->config->setName('FOOBAR');
104+
$this->assertEquals('FOOBAR', ini_get('session.name'));
105+
}
106+
107+
public function testIdempotentNameAltersIniSettingWithSameValueAfterSessionStart()
108+
{
109+
$this->config->setName('FOOBAR');
110+
session_start();
111+
112+
$this->config->setName('FOOBAR');
113+
$this->assertEquals('FOOBAR', ini_get('session.name'));
114+
}
115+
99116
// session.save_handler
100117

101118
public function testSaveHandlerDefaultsToIniSettings()

0 commit comments

Comments
 (0)