[英]Memcached Session Symfony 3.0 return error 500
I try to use symfony 3.0 Memcached session instead of default one. 我尝试使用symfony 3.0 Memcached会话而不是默认会话。
I configured my config.yml like this: 我这样配置config.yml:
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.yml:
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: 但是在网络上我收到错误500。原因是因为我这一行格式不正确:
arguments: ["@session.memcached", { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }
How I will give correcttrly the setting for memcached session on Symfony 3? 如何在Symfony 3上正确地为memcached会话设置?
EDIT 1: 编辑1:
My error.log says: 我的error.log说:
[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/symfon
[2016年7月4日星期一21:49:13.122413] [:错误] [pid 4244] [客户端127.0.0.1:50098] PHP致命错误:未捕获的Symfony \\ Component \\ Yaml \\ Exception \\ ParseException:格式错误的内联YAML字符串[“ @session .memcached“,{在第18行的前缀(%session_memcached_prefix%,到期时间:%session_memcached_expire%}(在参数“ [” @ session.memcached“,{前缀附近:%session_memcached_prefix%,到期时间:%session_memcached_expire%}”附近)主页/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 /供应商/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 / symfon y/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
y / src / Symfony / Component / Yaml / Parser.php(231):Symfony \\ Component \\ Yaml \\ Parser-> parseValue('[“ @ session.memc ...',false,false,位于/ home / pcmagas /第118行的Kwdikas / web / apps / symphotest / vendor / symfony / symfony / src / Symfony / Component / Config / Loader / FileLoader.php
Edit 2: 编辑2:
Also there is a new config.yml after a few comments suggested in coomments. 在库建议的一些注释之后,还有一个新的config.yml。
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 }
In the end the line that causes the problem should be: 最后,导致问题的行应为:
arguments: ["@session.memcached", { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }]
(The ] at the end of the entry was missing) (条目末尾的[]丢失)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.