Yii Framework Forum: Load Balancing And Session Management In Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Load Balancing And Session Management In Yii Load balancing and session management in yii Rate Topic: ***** 1 Votes

#1 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 876
  • Joined: 20-April 11
  • Location:India

Posted 29 March 2014 - 12:32 AM

How can i manage sessions between 2 or more web servers are using to manage Load balancing ?

The points that i found are

Use database session CDbHttpSession
Use cache session CCacheHttpSession
Use Security manager CSecurityManager
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 29 March 2014 - 01:54 AM

You can use memcached for that.
God is real unless declared as integer
0

#3 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 876
  • Joined: 20-April 11
  • Location:India

Posted 29 March 2014 - 04:02 AM

View PostORey, on 29 March 2014 - 01:54 AM, said:

You can use memcached for that.


Thank you .

ORey , is it successfully used by anyone?

The application should support web farms i.e. when multiple web servers are used to handle the load .
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#4 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 29 March 2014 - 04:07 AM

Well, memcached can use external IP, so why not?
Basically you just configure your apps to use the same memcache server, and that's it.
(probably you'll also need to check that the same session id is generated by your servers)
God is real unless declared as integer
0

#5 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 876
  • Joined: 20-April 11
  • Location:India

Posted 29 March 2014 - 04:14 AM

View PostORey, on 29 March 2014 - 04:07 AM, said:

Well, memcached can use external IP, so why not?
Basically you just configure your apps to use the same memcache server, and that's it.
(probably you'll also need to check that the same session id is generated by your servers)



okay. Thank you .

Please see the topic Multiserver . this is the issue I am facing .

And in this topic Yii forum post

see Gustavo 3rd reply .
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#6 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 876
  • Joined: 20-April 11
  • Location:India

Posted 29 March 2014 - 04:30 AM

You have a couple of options:

1) If your load balancer supports it, you can enable session persistence so that the user always is sent to the same server as the one they originally hit. The benefit of this is that it's easy to setup if you don't want to change any code. The downside is that if one of your servers goes down you lose all your sessions on that node.

2) Setup a shared memcache (not memcached) session between node1 and node2. The relevant settings being.

php.ini

session.save_handler memcache
session.save_path tcp://<ip1>, tcp://<ip2>
memcache.ini


memcache.allow_failover 1
memcache.default_port   11211
memcache.hash_strategy  standard
memcache.max_failover_attempts  20

It's a little tricky to setup, but once you get it working you have full redundancy between both servers if one were to go down.

3) Setup a third node to manage sessions and configure php session.save_path to be that server's ip. The benefit of this is that sessions are now managed by a third server. The downside being you lose redundancy, if that server goes down you lose sessions.

This is the best answer that i got . But I cant Use APC !!

Is there any other methods ?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#7 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 876
  • Joined: 20-April 11
  • Location:India

Posted 29 March 2014 - 05:02 AM

As Yii project Lead Qiang said , There is only one thing you need to be careful, that is the validationKey of CSecurityManager. By default, this key is automatically/randomly generated the first time and is stored under runtime directory. In multiple server environment, you should explicitly configure this property so that all servers share the same key. This key is used widely to generate hash keys for various security-related measures.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#8 User is offline   Boaz 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 367
  • Joined: 23-January 11

Posted 04 April 2014 - 01:57 AM

You'll need to use a non default php session handler. This goes beyond the scope of Yii only. I cannot give more information right now, as I'm writing via mobile phone. There are commercial products (load balancer among the rest), there are open source solutions as well, among which setting session handler via the Db. I never tested this with Yii though.
Therapeutic PHP sessions My LinkedIn Profile
0

#9 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 876
  • Joined: 20-April 11
  • Location:India

Posted 04 April 2014 - 07:00 AM

View PostBoaz, on 04 April 2014 - 01:57 AM, said:

You'll need to use a non default php session handler. This goes beyond the scope of Yii only. I cannot give more information right now, as I'm writing via mobile phone. There are commercial products (load balancer among the rest), there are open source solutions as well, among which setting session handler via the Db. I never tested this with Yii though.

ok. Thank you. please be detailed if you have time,when you are free.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users