Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 1.4 sessions randomly lost

This is an issue I've started to experiment a few months ago and I've been trying to fix without success since.

Symptoms: At random intervals of time symfony loses the session info and logs out the users. It seems somehow to be connected with the load of the site. When the load is higher it seems that the users are logged out more often, could happen even fast as 30 seconds.

Environment: Since this started I've changed a lot of the setup, including the php version, web server, session storage, symfony version. Here is the current setup: Ubuntu 10.04, php 5.4.0, symfony 1.4.17, nginx 1.0.15 with FPM. Here is how the session storage is configured in factories.yml:

  user:
    class: myUser
    param:
      timeout:         86400
      use_flash:       true
  storage:
    class: sfCacheSessionStorage
    param:
      cache:
        class: sfMemcacheCache
        param:
          lifetime:  86400
          host:      192.168.1.3
          serializer:  IGBINARY
          mode:        compiled
          port:        11211

I got to mention that I've also used redis for session storage and still had the problem. I really have no idea what to try next. Anybody else experienced something similar? At this stage any hint would be much appreciated.

Update: Ater months of searches and countless trials and errors I think it could be a concurrency problem. Our site is quite heavy on AJAX requests and I have learned that it can lead to issues with the sessions unless proper locking mechanisms are implemented in the session handler. First I have eliminated symfony from the equation, I've set it to use php sessions. With the default file session storage I never lose any sessions. Then I have configured php to use the memcache session storage. Surely enough we have started to see lost sessions. I am 100% positive that memcached is not running out of memory, I have installed an admin tool and the memcached server is barely using 2% of the 8GB allocated to it (no waste, the memory is allocated as needed). Then I have added a second memcached server and configured the session handler to use redundancy. This helped a lot, I rarely have any lost sessions. For now this is an acceptable compromise.

like image 540
dcb Avatar asked May 06 '12 14:05

dcb


1 Answers

For some reason, memcache seems to miss every now and again and create a new session which causes the user to be logged out.

As suggested by Jestep, you should prove this by taking memcache out of the equation to see if the problem goes away.

If so, then the problem is either the way you are talking to memcache or memcache itself.

like image 152
Lloyd Moore Avatar answered Sep 22 '22 12:09

Lloyd Moore