Memcached Session Symfony 3.0返回错误500

时间:2016-07-04 18:52:40

标签: php session memcached symfony

我尝试使用symfony 3.0 Memcached会话而不是默认会话。

我配置了我的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 }

我编辑了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% }

但是在网络上我得到错误500.原因是我这行不正确:

arguments: ["@session.memcached", { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }

我将如何正确地给出Symfony 3上memcached会话的设置?

编辑1:

我的error.log说:

  

[Mon Jul 04 21:49:13.122413 2016] [:error] [pid 4244] [客户   127.0.0.1:50098] PHP致命错误:未捕获的Symfony \ Component \ Yaml \ Exception \ ParseException:格式错误的内联   YAML string [“@ session.memcached”,{prefix:   %session_memcached_prefix%,expiretime:%session_memcached_expire%}   在第18行(靠近“arguments:[”@ session.memcached“,{prefix:   %session_memcached_prefix%,expiretime:%session_memcached_expire%}“)   在   /home/pcmagas/Kwdikas/web/apps/symphotest/vendor/symfony/symfony/src/Symfony/Component/Yaml/Inline.php:338\nStack   追踪:\ n#0   /home/pcmagas/Kwdikas/web/apps/symphotest/vendor/symfony/symfony/src/Symfony/Component/Yaml/Inline.php(63):   Symfony的\分量\ YAML \内嵌:: parseSequence( '[“@ session.memc ......',   101,数组)\ 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 \组件\ YAML \ Parser-> parseValue( '[“@ session.memc ...',   虚假,虚假,在   /home/pcmagas/Kwdikas/web/apps/symphotest/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php   在第118行

编辑2:

在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 }

1 个答案:

答案 0 :(得分:0)

最后导致问题的一行应该是:

arguments: ["@session.memcached", { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }]

(条目末尾的遗失)