[英]PHP - Memcached - Session Handling
So I need to alter my session handling from file based (default) to cache based, so when I add a node to the cluster, the session data is accessible to any app node in the cluster. 因此,我需要将会话处理从基于文件(默认)更改为基于缓存,因此,当我向集群添加节点时,集群中的任何应用程序节点都可以访问会话数据。
My experience has always been to centralize cache nodes using a config file, in my case, cache.yml. 我的经验一直是使用配置文件(在我的情况下为cache.yml)集中缓存节点。 With this file I identify 3 cache servers (vc-1, vc-2, vc3). 通过此文件,我确定了3个缓存服务器(vc-1,vc-2,vc3)。 Correct me if I am wrong, but as long as I use addServers call when creating my cache object, then use that cache object to set/get cache data, the data can be stored on any vc-* server, but as far as the app is concerned, it's a single (pooled) cache server. 如果我错了,请纠正我,但是只要我在创建缓存对象时使用addServers调用,然后使用该缓存对象设置/获取缓存数据,就可以将数据存储在任何vc- *服务器上,但是应用程序而言,它是一个(池)缓存服务器。 Example: 例:
After reading the php memecacheD docs , I can easily switch the session handling by way of the php.ini file, but then I would have to configure (puppetize) the php.ini file to build out the server string list, anytime I want to add/remove a new cache server, in order to maintain this pooling effect. 阅读php memecacheD 文档后 ,我可以通过php.ini文件轻松地切换会话处理,但是随后我必须配置(伪造)php.ini文件以构建服务器字符串列表,只要我想添加/删除新的缓存服务器,以保持这种池化效果。
So my question is, is there any other alternative other than implementing my own Session Handler , so that read/writes use the aforementioned cache object, to ensure a "pooled" caching effect, without having to edit the php.ini file? 所以我的问题是,除了实现自己的Session Handler之外 ,还有其他选择,以便读/写使用上述缓存对象,以确保“池化”缓存效果,而无需编辑php.ini文件吗?
I actually ended up using twemproxy , which is supposed to handle the addition/subtraction of memcached nodes based on health checks. 我实际上最终使用了twemproxy ,它应该基于运行状况检查处理memcached节点的加/减。 It was easy to setup, basically created a DNS record for vcache, and had the code point to vcache:22122. 它很容易设置,基本上为vcache创建了DNS记录,并且代码指向vcache:22122。
If using AWS, you can do the same thing but instead of twemproxy, setup an elasticache cluster, then create a CNAME dns entry which points to the elasticache endpoint. 如果使用AWS,则可以执行相同的操作,但是可以代替twemproxy,而是设置一个elasticache集群,然后创建一个指向Elasticache端点的CNAME dns条目。 This way you don't have to make a single code change, as the CNAME dns entry pointing to the elasticache endpoint will still resolve to vcache. 这样,您不必进行任何代码更改,因为指向Elasticache端点的CNAME dns条目仍将解析为vcache。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.