public function testRegisterSetsSessionSaveHandlerAndIniSettings()
 {
     ini_set('session.gc_probability', '0');
     $handler = SessionHandler::factory(array('dynamodb_client' => $this->getMockedClient(), 'automatic_gc' => true));
     $this->assertTrue($handler->register());
     $this->assertEquals('1', ini_get('session.gc_probability'));
     ini_set('session.gc_probability', '0');
 }
 public function register(Application $app)
 {
     parent::register($app);
     /** @noinspection PhpParamsInspection */
     $app['session.storage.handler'] = $app->share(function ($app) {
         $config = $app['session.dynamodb.options'];
         if (!array_key_exists('dynamodb_client', $config)) {
             $config['dynamodb_client'] = $this->getDynamoDbClient($app['aws']);
         }
         return SessionHandler::factory($config);
     });
     $app['session.dynamodb.options'] = array();
 }
 public function __construct()
 {
     $aws = Configure::read('Session.handler.aws');
     $dynamoDB = $aws->get('dynamodb');
     $config = array('dynamodb_client' => $dynamoDB, 'session_lifetime' => Configure::read('Session.timeout') * 60, 'table_name' => DynamoDBSession::DEFAULT_TABLE_NAME, 'locking_strategy' => 'pessimistic');
     if (Configure::check('Session.handler.table_name')) {
         $config['table_name'] = Configure::read('Session.handler.table_name');
     }
     if (Configure::check('Session.handler.locking_strategy')) {
         $config['locking_strategy'] = Configure::read('Session.handler.locking_strategy');
     }
     $this->_sessionHandler = SessionHandler::factory($config);
     if (Configure::check('Session.handler.session_name')) {
         $this->_sessionName = Configure::read('Session.handler.session_name');
     }
 }
 public function __construct($options, $table)
 {
     // refer to the Session class to find the session timeout value (if it exists)
     // in terms of DynamoDB, session_lifetime is the time to mark the inactive
     // session to be garbage collected
     // if {@link GarbageCollectSessionCronTask} is running periodically on your
     // server (via the silverstripe-crontask module), then the inactive session
     // will get removed from the DynamoDB session table.
     if (!isset($options['session_lifetime'])) {
         $timeout = Config::inst()->get('Session', 'timeout');
         if ($timeout != null) {
             $options['session_lifetime'] = $timeout;
         }
     }
     $this->client = DynamoDbClient::factory($options);
     $this->table = $table;
     $this->handler = SessionHandler::factory(array('dynamodb_client' => $this->client, 'table_name' => $this->table));
 }
Esempio n. 5
0
 /**
  * Convenience method for instantiating and registering the DynamoDB
  * Session handler with this DynamoDB client object.
  *
  * @param array $config Array of options for the session handler factory
  *
  * @return SessionHandler
  */
 public function registerSessionHandler(array $config = array())
 {
     $config = array_replace(array('dynamodb_client' => $this), $config);
     $handler = SessionHandler::factory($config);
     $handler->register();
     return $handler;
 }
 /**
  * Ensures that garbage collection functionality is working correctly
  */
 public function testGarbageCollection()
 {
     $currentCount = iterator_count($this->client->getIterator('Scan', array('TableName' => $this->table)));
     self::log('Put 10 expired items into the sessions table');
     $writeBatch = WriteRequestBatch::factory($this->client);
     for ($i = 1; $i <= 10; $i++) {
         $writeBatch->add(new PutRequest(Item::fromArray(array('id' => "example_{$i}", 'expires' => time() - 5 * Time::SECONDS)), $this->table));
     }
     $writeBatch->flush();
     self::log('Assert that all 10 items made it into the sessions table');
     $result = $this->client->getCommand('Scan', array('TableName' => $this->table))->execute();
     $this->assertEquals(10 + $currentCount, $result['Count'], 'Not all of the items were inserted.');
     self::log('Create a session handler to use with a lower batch size');
     $sh = SessionHandler::factory(array('dynamodb_client' => $this->client, 'table_name' => $this->table, 'gc_batch_size' => 3));
     self::log('Run the garbage collection');
     $sh->garbageCollect();
     self::log('Assert that all 10 items were deleted from the sessions table');
     $result = $this->client->getCommand('Scan', array('TableName' => $this->table))->execute();
     $this->assertEquals(0, $result['Count'], 'Not all of the items were removed.');
 }
Esempio n. 7
0
        $connexionString = "mysql:host=" . $config->db->mysql->host . ";dbname=" . $config->db->mysql->database;
        if ($config->db->mysql->logged) {
            $db = new LoggedPDO($connexionString, $config->db->mysql->user, $config->db->mysql->password, $pdo_options);
        } else {
            $db = new PDO($connexionString, $config->db->mysql->user, $config->db->mysql->password, $pdo_options);
        }
        $db->exec("SET time_zone='" . $offset . "';");
    } catch (Exception $e) {
        die("Erreur : " . $e->getMessage());
    }
    return $db;
}
function connect_dynamoDB($config)
{
    $client = DynamoDbClient::factory(array('key' => $config->aws->key, 'secret' => $config->aws->secret, 'region' => $config->aws->region));
    return $client;
}
if ($config->db->dynamoSessions) {
    require_once dirname(__FILE__) . '/../ext/autoload.php';
    $dynamoDB = connect_dynamoDB($config);
    // registering the dynamodb session handler performs some useless operations
    // in session!
    if (!isset($noSessions) || !$noSessions) {
        $sessionHandler = SessionHandler::factory(array('dynamodb_client' => $dynamoDB, 'table_name' => 'sessions', 'locking_strategy' => 'pessimistic', 'consistent_read' => true));
        $sessionHandler->register();
    }
}
if ($config->db->use != "dynamoDB" || !isset($noSQL) || !$noSQL) {
    // mysql is almost always used
    $db = connect_pdo($config);
}
 /**
  * @param \Aws\DynamoDb\DynamoDbClient $client
  * @param $config array
  */
 public function __construct(DynamoDbClient $client, array $config)
 {
     $this->client = $client;
     $config['dynamodb_client'] = $client;
     $this->handler = \Aws\DynamoDb\Session\SessionHandler::factory($config);
 }