Beispiel #1
0
 /**
  * @group 9294
  */
 public function testGcWithAutoQuoteIdentifiersEnabledAndDisabled()
 {
     $config = $this->_saveHandlerTableConfig;
     $configDb = array('options' => array('autoQuoteIdentifiers' => false), 'profiler' => true);
     $this->_setupDb($config['primary'], $configDb);
     $config['db'] = $this->_db;
     $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
     $saveHandler->gc(false);
     $lastQuery = $this->_db->getProfiler()->getLastQueryProfile()->getQuery();
     $partQueryExpected = "WHERE (modified + lifetime < ";
     $this->assertContains($partQueryExpected, $lastQuery);
     $configDb = array('options' => array('autoQuoteIdentifiers' => true), 'profiler' => true);
     $this->_setupDb($config['primary'], $configDb);
     $config['db'] = $this->_db;
     $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
     $saveHandler->gc(false);
     $lastQuery = $this->_db->getProfiler()->getLastQueryProfile()->getQuery();
     $partQueryExpected = "WHERE (\"modified\" + \"lifetime\" < ";
     $this->assertContains($partQueryExpected, $lastQuery);
 }
Beispiel #2
0
 public function testReadWriteThreeTimesAndGc()
 {
     $config = $this->_saveHandlerTableConfig;
     unset($config[Zend_Session_SaveHandler_DbTable::PRIMARY_ASSIGNMENT]);
     $config['primary'] = array($config['primary'][0]);
     $config['lifetime'] = 1;
     $this->_setupDb($config['primary']);
     $this->_usedSaveHandlers[] = $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
     $id = 242;
     $this->assertTrue($saveHandler->write($id, serialize($config)));
     $this->assertSame($config, unserialize($saveHandler->read($id)));
     $id++;
     $this->assertTrue($saveHandler->write($id, serialize($config)));
     $this->assertSame($config, unserialize($saveHandler->read($id)));
     $id++;
     $this->assertTrue($saveHandler->write($id, serialize($config)));
     $this->assertSame($config, unserialize($saveHandler->read($id)));
     foreach ($this->_db->query('SELECT * FROM Sessions')->fetchAll() as $row) {
         $this->assertSame($config, unserialize($row['data']));
     }
     sleep(2);
     $saveHandler->gc(false);
     foreach ($this->_db->query('SELECT * FROM Sessions')->fetchAll() as $row) {
         //should be empty!
         $this->fail();
     }
 }
 /**
  * Init session
  */
 protected function _initSession()
 {
     if (!$this->_appConfig->session_lifetime) {
         return;
     }
     // session storage db table
     $config = array('name' => 'sessions', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime');
     $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
     // run garbage collector in 1%
     if (rand(1, 100) == 1) {
         $saveHandler->gc(1);
     }
     // make the session persist for x seconds
     $saveHandler->setLifetime($this->_appConfig->session_lifetime, $this->_appConfig->session_lifetime);
     Zend_Session::setSaveHandler($saveHandler);
     Zend_Session::start(array('cookie_lifetime' => $this->_appConfig->session_lifetime));
 }