Last active
August 29, 2015 14:13
-
-
Save tristanlins/1570d80741130c2fe888 to your computer and use it in GitHub Desktop.
Use symfony memcached session handler in Contao
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ... | |
| /** | |
| * Symfony session storage | |
| */ | |
| $memcached = new \Memcached(); | |
| $memcached->addServer($GLOBALS['TL_CONFIG']['sessionMemcachedHost'], $GLOBALS['TL_CONFIG']['sessionMemcachedPort']); | |
| require TL_ROOT . '/composer/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php'; | |
| require TL_ROOT . '/composer/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php'; | |
| require TL_ROOT . '/composer/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/SessionBagInterface.php'; | |
| require TL_ROOT . '/composer/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php'; | |
| require TL_ROOT . '/composer/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php'; | |
| require TL_ROOT . '/composer/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php'; | |
| require TL_ROOT . '/composer/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php'; | |
| register_shutdown_function(function() { | |
| \Session::getInstance()->__destruct(); | |
| }); | |
| new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage( | |
| [], | |
| new \Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler( | |
| $memcached, | |
| ['prefix' => $GLOBALS['TL_CONFIG']['sessionMemcachedPrefix'] . $GLOBALS['TL_CONFIG']['encryptionKey'] . '_'] | |
| ) | |
| ); | |
| /** | |
| * Start the session | |
| */ | |
| @session_set_cookie_params(0, (TL_PATH ?: '/')); // see #5339 | |
| @session_start(); | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ### INSTALL SCRIPT START ### | |
| $GLOBALS['TL_CONFIG']['sessionMemcachedHost'] = 'localhost'; | |
| $GLOBALS['TL_CONFIG']['sessionMemcachedPort'] = 11211; | |
| $GLOBALS['TL_CONFIG']['sessionMemcachedPrefix'] = 'contao_session_'; | |
| ### INSTALL SCRIPT STOP ### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now it is configurable, put these three options into your localconfig.php and update the init script. Then you can change the settings from your localconfig.php. This may be helpful, when using syncCto or something similar.