Marcel Deglau Marcel Deglau - 1 year ago 158
Ajax Question

Symfony 2 AJAX session expire

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

to 0 but it made no difference. Here's also my security.yml:

pattern: ^/
anonymous: true
login_path: /home
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).

Answer Source

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

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

    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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download