To clarify, 3 different app servers utilizing 1 database server?
michael-hopkins said:
To clarify, 3 different app servers utilizing 1 database server?
Yep! Well it can be however many, just a elastic cloud sort of infrastructure.
For X app:1 db you SHOULD be able to set app\config\session.php
to database
instead of file. For example, here is mine
return array(
'driver' => 'database',
'lifetime' => 120,
'expire_on_close' => false,
'files' => storage_path().'/sessions',
'connection' => null,
'table' => 'sessions',
'lottery' => array(2, 100),
'cookie' => 'laravel_session',
'path' => '/',
'domain' => null,
'payload' => 'laravel_payload',
);
Then make sure you make the sessions table
class CreateSessionsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sessions', function(Blueprint $table) {
$table->increments('id');
$table->text('payload');
$table->integer('last_activity');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('sessions');
}
}
Then you should be able to call Session::put('data',$data);
on App server 1, and successfully call Session::get('data',$data)
on App server 2.
All of that said, its possible none of this will work. I just started playing around with sessions recently and have spent most of tonight struggling with them.
Yep I have all of that setup, however the problem doesn't seem to be Laravel storing the sessions in the database (lots of rows appearing), it's that when I refresh and land on whatever server, it doesn't seem to see me as the same user.
If I put
a session, then try calling it on another page it doesn't appear. Reasoning must be that as I hit one of the servers, apache sees me as a new user, thus I dont get associated as the same guy :(
I had this problem with a load balanced server previously. The load balancers were switching me every time I refreshed the page and therefore it was creating a new session.
My host has an option in the load balancers settings to keep users on the same node if they have an active session, which solved the problem.
darrencraig said:
I had this problem with a load balanced server previously. The load balancers were switching me every time I refreshed the page and therefore it was creating a new session.
My host has an option in the load balancers settings to keep users on the same node if they have an active session, which solved the problem.
Yeah "sticky sessions" I think they're called. Unfortunately I don't think that is an option. Blergh.
Seems to work with a memcached server... no idea what was going on with the database.
Would Redis session storage work as well?
what is the connection for the database? why is your's null? Please paste the exact connection. Should this be an array?
d8v15 said:
what is the connection for the database? why is your's null? Please paste the exact connection. Should this be an array?
Same question!
When you "Load-balance" use Sticky Sessions. Most Load Balancers have it. Sticky session means, once a request is catered (by a specific server in your cluster), all subsequent request will be directed to the same server.
It works with Memcached, even without sticky sessions because for all of Cache data (for all servers) is maintained in 1 single Memcache, even if its spread across different machines. Your Database driver wont work because, say my login session record is saved in 1 machine's "Sessions" table, how can it be checked across other machine's session table.
Another way to make it work would be to have a dedicated machine running the MySql or whatever DB you are using.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community