12
votes

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.

2
Are you using memcache as your session storage mechanism? If so, I should imagine memcache is throwing away a session as a new one comes in - memcache storage is not guaranteed, by design. Either increase the available memory to memcache, or better yet, use another persistence mechanism.halfer
As I mentioned I did use other session storage engines, as redis which doesn't throw away data. Besides I have never seen memcache to use more than 1GB, although is configured to use up to 8GB.dcb
Ah, I may have missed that - unless that detail was added in a subsequent edit. Is the behaviour exhibited on a dev server under test, perhaps using ab? Do you need PHP 5.4? If not, drop back done to 5.3.x, or even 5.2.x, and see if that makes a difference?halfer
I'm not sure what else to suggest. Can you replicate that loss of session with ab in a dev environment?halfer
Have you tried switching to a traditional session managing method to positively identify memcache as the problem?Jestep

2 Answers

1
votes

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.

0
votes

Actually the setup we have been using for the last few months is symfony configured to use the normal php sessions (not any of the cache classes) and then php is setup to use the memcache extention (there is another one called memcached) to store the session on 2 redundant memcache servers. If I take out one of the memcache servers we immediately start to see lost sessions.

This was the only setup that really did the job.