首页 > 解决方案 > Symfony:避免每个请求的会话

问题描述

我有一个基于 symfony 2.8 的应用程序,每个页面请求都会创建每个新会话。

例如,如果 /api/check 被调用 1000 次,则会不必要地创建 1000 个会话。

firewalls: # 禁用资产和分析器的身份验证,根据您的需要调整它 dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false

    api:
        pattern:  /api/
        anonymous: ~
        stateless:  true

    main:
        pattern: ^/
        form_login:
            # the user is redirected here when needed to log in
            login_path: security_login_register # URL: /willkommen

            # login handler via FOSUserBundle
            provider: fos_userbundle

            # name of input field of csrf token
            csrf_parameter: _csrf_token

            # token provider
            csrf_provider: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
            # DIRECTION OPTIONS:
            # /vendor/symfony/symfony/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php

            # OPTION 1: if set true, redirect always to default_target_path after login
            # DEFAULT: false
            always_use_default_target_path: false  # DEFAULT: false
            default_target_path: profile_order_list # URL: /profile/orders

            # OPTION 2: if option 1 not enabled, the URL of _target_path will be used for redirection
            # name of input field for redirection for form_login
            target_path_parameter: _target_path

            # OPTIONS 3: if option 1, 2 not enabled and user_refer is true, URL from $request->headers->get('Referer')
            # will be used for redirection
            # disabled using header referrer
            use_referer: false # DEFAULT: false

            # OPTION 4: if nothing found, URL of default_target_path will be used for redirection

            # do not remeber_me with higher security
            remember_me: false

        logout:
            path: fos_user_security_logout
            target: homepage  # URL: /
        anonymous:    true
        switch_user:  true

上面的块在安全配置中不起作用。我试图使 /api 路由无状态但不起作用,知道吗?

标签: symfonysymfony-2.8

解决方案


推荐阅读