PHP sessions in a load balancing cluster - how?

后端 未结 10 1960
粉色の甜心
粉色の甜心 2020-11-29 17:44

OK, so I\'ve got this totally rare an unique scenario of a load balanced PHP website. The bummer is - it didn\'t used to be load balanced. Now we\'re starting to get issues.

相关标签:
10条回答
  • 2020-11-29 18:21

    Might be too late, but check this out: http://www.pureftpd.org/project/sharedance

    Sharedance is a high-performance server to centralize ephemeral key/data pairs on remote hosts, without the overhead and the complexity of an SQL database.

    It was mainly designed to share caches and sessions between a pool of web servers. Access to a sharedance server is trivial through a simple PHP API and it is compatible with the expectations of PHP 4 and PHP 5 session handlers.

    0 讨论(0)
  • 2020-11-29 18:25

    When we had this situation we implemented some code that lives in a common header.

    Essentially for each page we check if we know the session Id. If we dont we check if we're in the situation whehich you describe, by checking if we have stored sesion data in the DB.Otherwise we just start a new session.

    Obviously this requires all relevant data to be copied to the DB, but if you encapsulate your session data in a seperate class then it works OK.

    0 讨论(0)
  • 2020-11-29 18:29

    If you are using php sessions you could share with NFS the /tmp directory, where I think the sessions are stored, between all the servers in the cluster. That way you don't need database.

    Edited: You can also use an external service like memcachedb (persistent and fast) and store the session info in the memcachedb index and indentify it with a hash of the content or even the session ID.

    0 讨论(0)
  • 2020-11-29 18:31

    The easiest thing to do is configure your load balancer to always send the same session to the same server.

    If you still want to use session_set_save_handler then maybe take a look at auto_prepend.

    0 讨论(0)
提交回复
热议问题