使用memcache作为会话存储? [英] Using memcache as a session store?

查看:124
本文介绍了使用memcache作为会话存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个巨大的问题。两天前我在一个服务器上运行的网站太多了,所以我再购买两个,并且将它们聚集(rsync和负载平衡)。

I currently have a huge problem. Two days ago my site running on one server was too much, so I purchased two more and had them clustered (rsync and load balanced).

然后我开始注意到用户会碰到服务器-1,然后在下一个请求命中server3,但他们的会话仍然在server1而不是server3,他们不再登录。

I then start noticing that a user would hit server-1 and then on the next request hit server3 but that their session was still on server1 instead of server3 and they were no longer logged in.

我是建议对会话存储使用memcache。

I was recommended to use memcache for session stores.

我的脚本已经使用 $ _ SESSION


  • 我们可以安装memcache并启用会话处理程序支持,并设置 session.save_handler =memcache 强制php使用memcache?

  • Can we get memcache installed and enable session handler support and set session.save_handler = "memcache" to force php to use memcache?

是否有任何应用程式需要使用记忆快取?

Is there any application programming that needs to be done to use memcache?

这会解决我在服务器问题之间的会话吗?

Will this solve my session between server issue?

会话存储在创建时是存储在所有服务器上还是类似主memcache服务器?

Are the session stores stored on all the servers when they are created or is one like a master memcache server?

我正在使用codeiginiter框架

I'm using the codeiginiter framework

推荐答案

您需要将内存缓存设置为在其中一个服务器上运行,并使所有服务器为会话使用相同的内存缓存实例。否则,如果他们每个都运行自己的memcache实例,你会有和以前一样的问题。

You would need to set up memcache to run on one of the servers and have all of the servers use that same memcache instance for the sessions. Otherwise, if they each run their own memcache instance, you'll have the same problem as before.

除了配置memcache,并告诉PHP使用它作为会话

Other than configuring memcache accordingly and telling PHP to use it as your session handler, you shouldn't have to make any changes to your code.

澄清建议我在这里,如果你将所有三个服务器组成一个单一的池,你不会有任何问题,只要每个PHP实例引用这些服务器在相同的顺序。 memcache使用客户端散列 ,因此您将确保相同的密钥在同一服务器上读/写。当然,如果您以任何方式更改该列表,则会话将失效。

To clarify the advice I gave here, if you group all three servers into a single pool, you won't have any problems as long as every PHP instance references those servers in the same order. memcache uses client side hashing, so you will be guaranteed that the same key is read / written on the same server. Of course, if you alter that list in any way, then sessions will become invalidated.

内存缓存开发人员甚至不建议您使用memcache存储会话数据因为它不是持久的,因此如果你必须重新启动内存缓存(或发生某些事情),那么所有的用户都将被注销。

The memcache developers actually don't even recommend that you use memcache for storing session data because it isn't persistent, and thus if you have to restart memcache (or something happens), then all of your users will be logged out.

这篇关于使用memcache作为会话存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆