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

Commit

Permalink
Merge pull request #106 from beastwick/development
Browse files Browse the repository at this point in the history
Fix for issue #84 Garbage set wrong way. GcMaxlifetime (session.gc_ma…
  • Loading branch information
michalbundyra committed Aug 11, 2019
2 parents 723d219 + 82454c7 commit 2f8d8aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SaveHandler/MongoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function gc($maxlifetime)
* each document. Doing so would require a $where query to work with the
* computed value (modified + lifetime) and be very inefficient.
*/
$microseconds = floor(microtime(true) * 1000) - $maxlifetime;
$microseconds = floor(microtime(true) * 1000) - $maxlifetime * 1000;

$result = $this->mongoCollection->deleteMany(
[
Expand Down
20 changes: 20 additions & 0 deletions test/SaveHandler/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ public function testGarbageCollection()
$this->assertEquals(0, $this->mongoCollection->count());
}

public function testGarbageCollectionMaxlifetimeIsInSeconds()
{
$saveHandler = new MongoDB($this->mongoClient, $this->options);
$this->assertTrue($saveHandler->open('savepath', 'sessionname'));

$data = ['foo' => 'bar'];

$this->assertTrue($saveHandler->write(123, serialize($data)));
sleep(1);
$this->assertTrue($saveHandler->write(456, serialize($data)));
$this->assertEquals(2, $this->mongoCollection->count());

// Clear everything what is at least 1 second old.
$saveHandler->gc(1);
$this->assertEquals(1, $this->mongoCollection->count());

$this->assertEmpty($saveHandler->read(123));
$this->assertNotEmpty($saveHandler->read(456));
}

/**
* @expectedException \MongoDB\Driver\Exception\RuntimeException
*/
Expand Down

0 comments on commit 2f8d8aa

Please sign in to comment.