From ba213bfcbec72e10ff62a8ff27a1cfb9523c0503 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Mon, 13 Apr 2015 14:28:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=9B=86=E6=88=90=E7=8E=AF?= =?UTF-8?q?=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/memcache.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/think/cache/driver/memcache.php b/library/think/cache/driver/memcache.php index 796b98fc..e3cd635f 100644 --- a/library/think/cache/driver/memcache.php +++ b/library/think/cache/driver/memcache.php @@ -40,9 +40,16 @@ class Memcache { } $func = $this->options['persistent'] ? 'pconnect' : 'connect'; $this->handler = new \Memcache; - $options['timeout'] === false ? - $this->handler->$func($options['host'], $options['port']) : - $this->handler->$func($options['host'], $options['port'], $options['timeout']); + // 支持集群 + $hosts = explode(',', $this->options['host']); + $ports = explode(',', $this->options['port']); + + foreach((array) $hosts as $i=>$host){ + $port = isset($ports[$i]) ? $ports[$i] : $ports[0]; + $options['timeout'] === false ? + $this->handler->addServer($host, $port, $this->options['persistent'], 1) : + $this->handler->addServer($host, $port, $this->options['persistent'], 1, $this->options['timeout']); + } } /**