weixin_33749131 2016-10-04 14:47 采纳率: 0%
浏览 33

Symfony 2 AJAX会话到期

I have an AJAX worker they is called a API url every second. After 250-300 seconds, I don't get a valid response or a profile-token in case of the user was logged out. I have already configured the cookie_lifetime to 0 but it made no difference. Here's also my security.yml:

firewalls:
    main:
        pattern: ^/
        anonymous: true
        form_login:
            login_path: /home
        logout:
            path: logout
            handler: app.custom_logout
            target: /home

The weird thing is, it seems completely random when a session expires. I have also reached over 1000 AJAX calls and on the other side only 300 calls.

I hope any one of you can help me.

PS: The AJAX calls are not only a JSON response, there are full generated twig templates (including a profiler).

  • 写回答

1条回答 默认 最新

  • weixin_33725272 2016-10-10 20:20
    关注

    I've found an answer for my question by myself.

    You need to configure the gc_divisor, gc_probability and gc_maxlifetime. For example:

    session:
        cookie_lifetime: 0
        gc_divisor: 10000
        gc_probability: 1
        gc_maxlifetime: 604800
    

    After this configuration in your config.yml the chance that your session expire (because you have set cookie_lifetime to a specific time) is equal to zero.

    Also have a look to the Symfony documentation of sessions: http://symfony.com/doc/current/reference/configuration/framework.html#session

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元