/** * @param \Wandu\Http\Contracts\SessionInterface $session * @param \Wandu\Http\Contracts\CookieJarInterface $cookieJar * @return \Wandu\Http\Contracts\SessionInterface $session */ public function toCookieJar(SessionInterface $session, CookieJarInterface $cookieJar) { $sessionName = $this->config['name']; // save to handler $this->handler->write($session->getId(), serialize($session->getRawParams())); // apply to cookie-jar $cookieJar->set($sessionName, $session->getId(), (new DateTime())->setTimestamp(time() + $this->config['timeout'])); // garbage collection $pick = rand(1, max(1, $this->config['gc_frequency'])); if ($pick === 1) { $this->handler->gc($this->config['timeout']); } return $session; }
public function testGarbageCollection() { $countOfSessionFiles = $this->getCountOfSessionFiles(); $this->adapter->write('1', 'string 1'); $this->adapter->write('2', 'string 2'); $this->adapter->write('3', 'string 3'); // increase 3 files $this->assertEquals($this->getCountOfSessionFiles(), $countOfSessionFiles + 3); $this->assertTrue($this->adapter->gc(1)); $this->assertEquals('string 1', $this->adapter->read('1')); $this->assertEquals('string 2', $this->adapter->read('2')); $this->assertEquals('string 3', $this->adapter->read('3')); sleep(2); $this->assertTrue($this->adapter->gc(1)); // decrease 3 files $this->assertEquals($this->getCountOfSessionFiles(), $countOfSessionFiles); $this->assertEquals('', $this->adapter->read('1')); $this->assertEquals('', $this->adapter->read('2')); $this->assertEquals('', $this->adapter->read('3')); }
protected function collectGarbage() { $probability = $this->options->getInt('gc_probability'); if ($probability < 0) { return; } $divisor = $this->options->getInt('gc_divisor'); $rand = mt_rand(0, $divisor); if ($rand < $probability) { $this->handler->gc($this->options->getInt('gc_maxlifetime')); } }
/** * {@inheritdoc} */ public function gc($maxlifetime) { return (bool) $this->handler->gc($maxlifetime); }
/** * {@inheritdoc} */ public function gc($maxLifetime) { return $this->wrappedSessionHandler->gc($maxLifetime); }
/** * {@inheritdoc} */ public function gc($max_lifetime) { return $this->sessionHandler->gc($max_lifetime); }