From faaf99c036b0e81aab715f4cee861e6b6fdc2ffe Mon Sep 17 00:00:00 2001 From: 7IN0SAN9 Date: Wed, 27 Jan 2016 21:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20Memcache=20=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E4=B8=BA=20Memcached=20=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../driver/{Memcache.php => Memcached.php} | 24 +++++++++---------- .../driver/{Memcache.php => Memcached.php} | 14 +++++------ 2 files changed, 17 insertions(+), 21 deletions(-) rename library/think/cache/driver/{Memcache.php => Memcached.php} (85%) rename library/think/session/driver/{Memcache.php => Memcached.php} (85%) diff --git a/library/think/cache/driver/Memcache.php b/library/think/cache/driver/Memcached.php similarity index 85% rename from library/think/cache/driver/Memcache.php rename to library/think/cache/driver/Memcached.php index 2d18799e..4fbfe735 100644 --- a/library/think/cache/driver/Memcache.php +++ b/library/think/cache/driver/Memcached.php @@ -18,16 +18,16 @@ use think\Exception; * Memcache缓存驱动 * @author liu21st */ -class Memcache +class Memcached { protected $handler = null; protected $options = [ - 'host' => '127.0.0.1', - 'port' => 11211, - 'expire' => 0, - 'timeout' => 1, - 'persistent' => false, - 'length' => 0, + 'host' => '127.0.0.1', + 'port' => 11211, + 'expire' => 0, + 'timeout' => 1, + //'persistent' => false, + 'length' => 0, ]; /** @@ -37,22 +37,20 @@ class Memcache */ public function __construct($options = []) { - if (!extension_loaded('memcache')) { - throw new Exception('_NOT_SUPPERT_:memcache'); + if (!extension_loaded('memcached')) { + throw new Exception('_NOT_SUPPERT_:memcached'); } if (!empty($options)) { $this->options = array_merge($this->options, $options); } - $this->handler = new \Memcache; + $this->handler = new \Memcached; // 支持集群 $hosts = explode(',', $this->options['host']); $ports = explode(',', $this->options['port']); foreach ((array) $hosts as $i => $host) { $port = isset($ports[$i]) ? $ports[$i] : $ports[0]; - false === $options['timeout'] ? - $this->handler->addServer($host, $port, $this->options['persistent'], 1) : - $this->handler->addServer($host, $port, $this->options['persistent'], 1, $this->options['timeout']); + $this->handler->addServer($host, $port, 1); } } diff --git a/library/think/session/driver/Memcache.php b/library/think/session/driver/Memcached.php similarity index 85% rename from library/think/session/driver/Memcache.php rename to library/think/session/driver/Memcached.php index 869d9d2c..0ba4fd80 100644 --- a/library/think/session/driver/Memcache.php +++ b/library/think/session/driver/Memcached.php @@ -14,7 +14,7 @@ namespace think\session\driver; use SessionHandler; use think\Exception; -class Memcache extends SessionHandler +class Memcached extends SessionHandler { protected $handler = null; protected $config = [ @@ -22,7 +22,7 @@ class Memcache extends SessionHandler 'port' => 1121, // 端口 'expire' => 3600, // 有效期 'timeout' => 1, // 超时时间 - 'persistent' => 0, // 是否长连接 + //'persistent' => 0, // 是否长连接 'session_name' => '', // memcache key前缀 ]; @@ -40,19 +40,17 @@ class Memcache extends SessionHandler public function open($savePath, $sessName) { // 检测php环境 - if (!extension_loaded('memcache')) { - throw new Exception('_NOT_SUPPERT_:memcache'); + if (!extension_loaded('memcached')) { + throw new Exception('_NOT_SUPPERT_:memcached'); } - $this->handler = new \Memcache; + $this->handler = new \Memcached; // 支持集群 $hosts = explode(',', $this->config['host']); $ports = explode(',', $this->config['port']); // 建立连接 foreach ((array) $hosts as $i => $host) { $port = isset($ports[$i]) ? $ports[$i] : $ports[0]; - false === $this->config['timeout'] ? - $this->handler->addServer($host, $port, $this->config['persistent'], 1) : - $this->handler->addServer($host, $port, $this->config['persistent'], 1, $this->config['timeout']); + $this->handler->addServer($host, $port, 1); } return true; }