Knowledgebase

Sharing sessions between servers in cluster

Posted by king12345, 04-06-2010, 07:24 AM
Hello, how do you share PHP sessions between servers in cluster ? Our cluster is balanced by server load and every request goes to different server. PHP sessions are usually saved in /usr/lib/php5, we tried to share this directory between servers using NFS, but NFS doesnt like thousands of small files. We also tried memcached, but the most of CMS has session.save_handler set to file which caused problems. Any ideas ? With best regards King

Posted by vapetrov, 04-06-2010, 10:01 AM
How do you synchronize user's files on all servers? Seems best way for you is to bind users to server by ip. Some load balancers can do it.

Posted by king12345, 04-06-2010, 10:30 AM
User files are mounted to every server using NFS. Its possible to send every web to some server (if is alive), but our system checks every server load and than decide to which server will request send.

Posted by vapetrov, 04-06-2010, 12:34 PM
Load balancing per session (per ip) shall work same fine like balancing per request if you have a lot of visitors. For NFS you can try to perform same optimization to low nfs latency. But it will not helps significantly. I suggest you to use memcache session storage by default. I guess the best way to prevent users to set session.save_handler is by means of users persuasion. The forced ways like recompile php without "files" session storage support look to cruel.

Posted by king12345, 04-06-2010, 12:39 PM
What happen if someone will try to set session.save_handler to files and this option will not be compilled in ?

Posted by squirrelhost, 04-06-2010, 03:08 PM
Is this simply running your own website(s), or multiple websites using shared hosting? If it's your own, you can choose one (or more) of the servers to act as a 'session' server. You can roll your own code to do this if you feel adventurous, or you can use one of several off-the-shelf solutions. Not wishing to preach for one solution as the best, if you wish you can PM me for a quick solution.

Posted by vapetrov, 04-06-2010, 05:09 PM
Error. So, users will forced to edit CMS options or php code.

Posted by cselzer, 04-06-2010, 05:13 PM
you could write a custom session handler to do it with a database of some sort. Whether it be sql server, mysql, postgresql... Just a thought. Or mount drives like mentioned previously.



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
Root or Not (Views: 619)


Language:

Client Login

Email

Password

Remember Me

Search