Ask your Symfony questions! Pay money and get answers fast! (more info)

How to handle intermittent log and log out? Symfony

  • SOLVED

We have a site that sits behind a load balancer. Behind the load balancer, we have 4 servers. They are identical in all ways. Separate from that, we have a database server.

We are using Propel and the sfGuardUser plugin. Symfony 1.0. The login is very strange and intermittent. If you log in, the next page might say you are logged out, the page after that might say you are again logged in, the page after that might say you are again logged out.

In fact, if you stay on the same page and hit refresh over and over, you might get:

logged in

logged in

logged out

logged out

logged out

logged in

logged in

etc

I'm guessing this has something to do with cookies and the servers and the load balancer? If yes, how do we test?

If no, what other possibilities are there?


UPDATE:

So, okay, this is almost certainly because session info is not being shared between the 4 servers. What is the most common way to get this working with Symfony?


UPDATE:

I am looking here:

http://www.symfony-project.org/book/1_0/06-Inside-the-Controller-Layer

we have something like this:

all:
storage:
class: sfMySQLSessionStorage
param:
db_table: SESSION_TABLE_NAME # Name of the table storing the sessions
database: DATABASE_CONNECTION # Name of the database connection to use

We are using a database like the one described here:

http://grahamc.com/blog/how-to-setup-sfpdosessionstorage


If we click the "Keep my logged in" button, then the login works, but otherwise it does not work.

We are using sfGuardUserPlugin for user management.

Any thoughts why the regular login (just using session data) does not work?


Answers (2)

2010-09-17

Florian Klein answers:

Hello,

you may want to use a more scalable session Storage mecanism, like a database for example. Symfony comes with this kind of storage: you should be able to enable it from your app/config/factories.yml.

look at available options in the symfony doc, in the Reference book:

http://www.symfony-project.org/reference/1_4/en/05-Factories#chapter_05_storage


Lawrence Krubner comments:

On what page of the reference book? You should post an URL. The reason why I'm offering money as a prize is because I'm in a huge hurry.


Florian Klein comments:

Sorry for the inconvenience. here is a link to available storage options

So I repost the link pointing to the 1.0 documentation: http://www.symfony-project.org/api/1_0/storage

2010-09-17

Pascal answers:

Hi,

I think you should check this plugin :

http://www.symfony-project.org/plugins/sfCookieSessionStoragePlugin

sfCookieSessionStoragePlugin is a cookie-based session storage plugin for the symfony framework. Using this storage, the session data is directly stored in a cookie, only on the client side (no persistent session on the server side).
This removes the need for a shared session storage in a load-balanced platform, since a request from the user also carries the session data. As compared with other solutions for load-balanced session (database or memcache storage), cookie-based session storage is easier to install, and much faster.

Credits to the author : Francois Zaninotto


Lawrence Krubner comments:

Sadly, we are using Symfony 1.0


Pascal comments:

I've check the source and I don't see anything incompatible with symfony 1.0 you should download it and give it a try.

http://plugins.symfony-project.org/get/sfCookieSessionStoragePlugin/sfCookieSessionStoragePlugin-0.9.2.tgz


Pascal comments:

Don't you have an option on your load balancer called "sticky session" ?

This options assign one specific server to each new user connecting to your website, and each new request is always directed to that same server.

With that option you don't have to deal with session storage on memcached/key storage/mysql.


Pascal comments:

Other thing : since you are using database to store session take care to not enabling cache of query or result. That could explain your problem.