From 749593d1c3edff5b910a529f468eef47949bcb2d Mon Sep 17 00:00:00 2001 From: Drak Date: Wed, 21 Mar 2012 09:07:23 +0545 Subject: [PATCH] [FrameworkBundle] Allow configuration of session garbage collection for session 'keep-alive'. --- CHANGELOG-2.1.md | 6 ++++++ .../FrameworkBundle/DependencyInjection/Configuration.php | 3 +++ .../DependencyInjection/FrameworkExtension.php | 2 +- .../FrameworkBundle/Resources/config/schema/symfony-1.0.xsd | 3 +++ .../Tests/DependencyInjection/Fixtures/php/full.php | 3 +++ .../Tests/DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 3 +++ .../Tests/DependencyInjection/FrameworkExtensionTest.php | 3 +++ 8 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 21edb0f197..1082c244c8 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -52,6 +52,12 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c 'httponly' are now prefixed with cookie_ when dumped to the container * Added `handler_id` configuration under `session` key to represent `session.handler` service, defaults to `session.handler.native_file`. + * Added `gc_maxlifetime` (default 86400 seconds), `gc_probability` (default 1), + and `gc_divisor` (default 100) to session configuration. This means session + garbage collection has 1/100 chance of being run. The `gc_maxlifetime` means + how long a session can idle for which is separate from cookie lifetime which + defines how long a cookie can be store on the remote client. + ### MonologBundle diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 652531d613..a1b4ce7554 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -175,6 +175,9 @@ class Configuration implements ConfigurationInterface ->scalarNode('cookie_domain')->end() ->booleanNode('cookie_secure')->end() ->booleanNode('cookie_httponly')->end() + ->scalarNode('gc_divisor')->defaultValue(100)->end() + ->scalarNode('gc_probability')->defaultValue(1)->end() + ->scalarNode('gc_maxlifetime')->defaultValue(86400)->end() ->scalarNode('lifetime')->setInfo('DEPRECATED! Please use: cookie_lifetime')->end() ->scalarNode('path')->setInfo('DEPRECATED! Please use: cookie_path')->end() ->scalarNode('domain')->setInfo('DEPRECATED! Please use: cookie_domain')->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 8c91c37a4e..335f1f4d24 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -295,7 +295,7 @@ class FrameworkExtension extends Extension // session storage $container->setAlias('session.storage', $config['storage_id']); $options = array(); - foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'auto_start') as $key) { + foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'auto_start', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) { if (isset($config[$key])) { $options[$key] = $config[$key]; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 8b7c264ce2..124c25b467 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -90,6 +90,9 @@ + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index 32fa1812fa..79cc18a969 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -28,6 +28,9 @@ $container->loadFromExtension('framework', array( 'domain' => 'example.com', 'secure' => true, 'httponly' => true, + 'gc_maxlifetime' => 90000, + 'gc_divisor' => 108, + 'gc_probability' => 1, ), 'templating' => array( 'assets_version' => 'SomeVersionScheme', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 5ee785070e..494223ea38 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -12,7 +12,7 @@ - + loader.foo loader.bar diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index dd459e784f..4c9bdebf0a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -22,6 +22,9 @@ framework: domain: example.com secure: true httponly: true + gc_probability: 1 + gc_divisor: 108 + gc_maxlifetime: 90000 templating: assets_version: SomeVersionScheme assets_base_urls: http://cdn.example.com diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 43ae49a016..3b951bbb03 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -88,6 +88,9 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertEquals('example.com', $options['cookie_domain']); $this->assertTrue($options['cookie_secure']); $this->assertTrue($options['cookie_httponly']); + $this->assertEquals(108, $options['gc_divisor']); + $this->assertEquals(1, $options['gc_probability']); + $this->assertEquals(90000, $options['gc_maxlifetime']); } public function testSessionDeprecatedMergeFull()