-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[HttpFoundation][Sessions] Losing session in case of many concurrent requests. #4668
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dabedc1
[HttpFoundation][Sessions] Added flocks to read and write methods and…
yanoosh a4dc42d
[HttpFoundation][Sessions] Fixed code formatting.
yanoosh 75d4890
[HttpFoundation][Sessions] Fix. Added variable declaration above if a…
yanoosh a56d733
[HttpFoundation][Sessions] Added locking session during a request - …
yanoosh cc841b5
[HttpFoundation][Sessions] Fix. Function session_write_close always i…
yanoosh 0f242ac
[HttpFoundation][Sessions] Test case should call only one method from…
yanoosh ce71c4e
[HttpFoundation][Sessions] Added test.
yanoosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,15 @@ class FileSessionStorageTest extends \PHPUnit_Framework_TestCase | |
*/ | ||
private $path; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $prefix = 'mocksess_'; | ||
|
||
public function setUp() | ||
{ | ||
$this->path = sys_get_temp_dir().'/filesessionhandler'; | ||
$this->handler = new FileSessionHandler($this->path, 'mocksess_'); | ||
$this->handler = new FileSessionHandler($this->path, $this->prefix); | ||
|
||
parent::setUp(); | ||
} | ||
|
@@ -73,26 +78,27 @@ public function testReadWrite() | |
|
||
public function testDestroy() | ||
{ | ||
$this->handler->write('456', 'data'); | ||
$pathPrefix = $this->path.'/'.$this->prefix; | ||
file_put_contents($pathPrefix.'456', 'data'); | ||
$this->handler->destroy('123'); | ||
$this->assertEquals('data', $this->handler->read('456')); | ||
$this->assertEquals('data', file_get_contents($pathPrefix . '456')); | ||
$this->handler->destroy('456'); | ||
$this->assertEmpty($this->handler->read('456')); | ||
$this->assertFalse(is_file($pathPrefix . '456')); | ||
} | ||
|
||
public function testGc() | ||
{ | ||
$prefix = $this->path.'/mocksess_'; | ||
$this->handler->write('1', 'data'); | ||
$prefix = $this->path.'/'.$this->prefix; | ||
file_put_contents($prefix.'1', 'data'); | ||
touch($prefix.'1', time()-86400); | ||
|
||
$this->handler->write('2', 'data'); | ||
file_put_contents($prefix.'2', 'data'); | ||
touch($prefix.'2', time()-3600); | ||
|
||
$this->handler->write('3', 'data'); | ||
file_put_contents($prefix.'3', 'data'); | ||
touch($prefix.'3', time()-300); | ||
|
||
$this->handler->write('4', 'data'); | ||
file_put_contents($prefix.'4', 'data'); | ||
|
||
$this->handler->gc(90000); | ||
$this->assertEquals(4, count(glob($this->path.'/*'))); | ||
|
@@ -103,4 +109,13 @@ public function testGc() | |
$this->handler->gc(200); | ||
$this->assertEquals(1, count(glob($this->path.'/*'))); | ||
} | ||
|
||
/** | ||
* @expectedException RuntimeException | ||
*/ | ||
public function testOneSessionAtTime() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is pointless. PHP handles this by itself. |
||
{ | ||
$this->handler->read(1); | ||
$this->handler->read(2); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This condition will never occur because PHP will only open one session at a time.
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.
After session_start you can change session id. PHP allows for this type of behaviour and not throwing any error. I think the better solution will be inform user that he do something wrong trying to change session id.
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 cannot introduce behaviour than already exists in PHP sessions. Doing so will create inconsistencies across drivers. This is simply a storage device that is called by PHP itself and not invoked by user-land code and therefore we must and should not interfere. If you believe the behaviour of PHP sessions wrong, you would be quite correct, but that is a matter for PHP core.