Last active
April 5, 2017 05:04
-
-
Save stormsson/7145da9162f2a5f3f92a to your computer and use it in GitHub Desktop.
Symfony2 Session management
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
# app/config.yml | |
framework: | |
... | |
session: | |
handler_id: %session_handler_id% # read from parameters.yml | |
#handler_id: session.handler.memcache # use service defined later | |
services: | |
# MEMCACHE SESSION MANAGEMENT SERVICE CONFIGURATION | |
session.memcache: | |
class: Memcache | |
arguments: | |
persistent_id: %session_memcache_prefix% | |
calls: | |
- [ addServer, [ %session_memcache_host%, %session_memcache_port% ]] | |
session.handler.memcache: | |
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler | |
arguments: [@session.memcache, { prefix: %session_memcache_prefix%, expiretime: %session_memcache_expire% }] | |
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
# app/config.yml | |
framework: | |
... | |
session: | |
handler_id: %session_handler_id% # read from parameters.yml | |
#handler_id: session.handler.pdo # use service defined later | |
parameters: | |
# PARAMETERS FOR PDO SESSION MANAGEMENT | |
pdo.db_options: | |
db_table: session | |
db_id_col: session_id | |
db_data_col: session_value | |
db_time_col: session_time | |
services: | |
# PDO SESSION MANAGEMENT SERVICE CONFIGURATION | |
pdo: | |
class: PDO | |
arguments: | |
dsn: "mysql:dbname=%database_name%;host=%database_host%" | |
user: %database_user% | |
password: %database_password% | |
calls: | |
- [setAttribute, [3, 2]] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION | |
session.handler.pdo: | |
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler | |
arguments: ["@pdo", %pdo.db_options%] |
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
# app/config/parameters.yml | |
session_memcache_host: localhost | |
session_memcache_port: 11211 | |
session_memcache_prefix: sess | |
session_memcache_expire: 3600 | |
session_handler_id: null # which session handler to use. null = use php; ignores previous parameters | |
#session_handler_id: session.handler.pdo # use PDO | |
#session_handler_id: session.handler.memcache # use memcache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment