Sessions not holding on AppFog / Laravel 3

450 views Asked by At

Im not sure what could be causing this, But my project has been working fine in development.

But when I uploaded it to AppFog, suddenly my sessions/Auth() wont hold.

Authentication works to login. So a user can login, and will be redirected to their profile page... and from there they can update stuff...

So Auth() is obviously holding their session, but wierdly when they click anywhere else on the site, away from their profile.....suddenly their session is lost. And they have to re-login again if they want to navigate back to their profile.

Why would this happen in production but not development. The codebase is exactly the same. Only difference is im using Local/Production database settings, thats it. Other than that everything else is exactly the same.

Any idea what could be causing this?? Normally I would check php.ini and such, but on appfog, I doubt you can access any of the deep admin stuff.

Should I just switch from session based auth, to Redis/Database auth??? Anybody else come across this problem on AppFog, with Laravel, or YII?

UPDATE

Switching from default, to database session storage produced a strange error, of multiple entries per login. Which of course makes the Auth()attempt fail. I fixed this, by removing auto_increment on the id column of the sessions table. This fixed my one app....that was working before on the default settings.

The other app in question still does not work. It at least is now only making 1 entry in the session table on login attempt, but for some reason it isnt creating a login cookie to cross reference with that table.

In Chrome Console, under resources on the working app I have...

laravel_session -> 6

Which is referring to the id 6 in the session table, hence why it works.

In the non-working app however.....I have

laravel_session - > 41g1D4390Sd223s etc etc

Which as far as I can tell, isn't referring to anything....

Any insight on this???

2

There are 2 answers

3
itachi On

i had similiar problem with both laravel3 and laravel4.

The workaround (though not recommended) is,

use Session::save() manually after putting anything in the Session.

e.g.

Session::put('foo','bar');
Session::save();

As i found it, sometimes laravel fails to call Session::save() and does not throw any exceptions or errors.

4
Dwight On

This could be because AppFog is a cloud based service without persistent data storage. By default, Laravel uses disk storage for it's sessions. Switch to storing your sessions in the database and they should be maintained correctly.