I try to use symfony 3.0 Memcached session instead of default one.
I configured my config.yml like this:
imports:
- { resource: params.php }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.memcached
session_memcached_host: 127.0.0.1
session_memcached_port: 11211
session_memcached_prefix: ng_
session_memcached_expire: 43200
fragments: ~
http_method_override: true
assets: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
encryption: "%mailer_encryption_method%"
port: "%mailer_port%"
spool: { type: memory }
And I edited the services.yml like that:
services:
session.memcached:
class: Memcached
arguments:
persistent_id: %session_memcached_prefix%
calls:
- [ addServer, [ %session_memcached_host%, %session_memcached_port% ]]
session.handler.memcached:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
arguments: ["@session.memcached", { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }
But on the network I get error 500. The reason is because I this line is malformed:
arguments: ["@session.memcached", { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }
How I will give correcttrly the setting for memcached session on Symfony 3?
EDIT 1:
My error.log says:
[Mon Jul 04 21:49:13.122413 2016] [:error] [pid 4244] [client 127.0.0.1:50098] PHP Fatal error: Uncaught Symfony\Component\Yaml\Exception\ParseException: Malformed inline YAML string ["@session.memcached", { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% } at line 18 (near "arguments: ["@session.memcached", { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }") in /home/pcmagas/Kwdikas/web/apps/symphotest/vendor/symfony/symfony/src/Symfony/Component/Yaml/Inline.php:338\nStack trace:\n#0 /home/pcmagas/Kwdikas/web/apps/symphotest/vendor/symfony/symfony/src/Symfony/Component/Yaml/Inline.php(63): Symfony\Component\Yaml\Inline::parseSequence('["@session.memc...', 101, Array)\n#1 /home/pcmagas/Kwdikas/web/apps/symphotest/vendor/symfony/symfony/src/Symfony/Component/Yaml/Parser.php(498): Symfony\Component\Yaml\Inline::parse('["@session.memc...', false, false, false, Array)\n#2 /home/pcmagas/Kwdikas/web/apps/symphotest/vendor/symfony/symfony/src/Symfony/Component/Yaml/Parser.php(231): Symfony\Component\Yaml\Parser->parseValue('["@session.memc...', false, false, in /home/pcmagas/Kwdikas/web/apps/symphotest/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php on line 118
Edit 2:
Also there is a new config.yml after a few comments suggested in coomments.
imports:
- { resource: params.php }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
session_memcached_host: 127.0.0.1
session_memcached_port: 11211
session_memcached_prefix: ng_
session_memcached_expire: 43200
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.memcached
fragments: ~
http_method_override: true
assets: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
encryption: "%mailer_encryption_method%"
port: "%mailer_port%"
spool: { type: memory }
session_memcached_*
are parameters so put it under theparameters
key in the config.yml – Matteo