改进session驱动

This commit is contained in:
thinkphp
2016-09-09 11:44:53 +08:00
parent 827edfc7b9
commit ebaaf6181c
2 changed files with 5 additions and 5 deletions

View File

@@ -19,7 +19,7 @@ class Memcache extends SessionHandler
protected $handler = null;
protected $config = [
'host' => '127.0.0.1', // memcache主机
'port' => 1121, // memcache端口
'port' => 11211, // memcache端口
'expire' => 3600, // session有效期
'timeout' => 0, // 连接超时时间(单位:毫秒)
'persistent' => true, // 长连接
@@ -54,7 +54,7 @@ class Memcache extends SessionHandler
foreach ((array) $hosts as $i => $host) {
$port = isset($ports[$i]) ? $ports[$i] : $ports[0];
$this->config['timeout'] > 0 ?
$this->handler->addServer($host, $port, $this->config['persistent'], 1, $this->config['timeout']) :
$this->handler->addServer($host, $port, $this->config['persistent'], 1, $this->config['timeout']) :
$this->handler->addServer($host, $port, $this->config['persistent'], 1);
}
return true;

View File

@@ -19,7 +19,7 @@ class Memcached extends SessionHandler
protected $handler = null;
protected $config = [
'host' => '127.0.0.1', // memcache主机
'port' => 1121, // memcache端口
'port' => 11211, // memcache端口
'expire' => 3600, // session有效期
'timeout' => 0, // 连接超时时间(单位:毫秒)
'session_name' => '', // memcache key前缀
@@ -61,9 +61,9 @@ class Memcached extends SessionHandler
$servers[] = [$host, (isset($ports[$i]) ? $ports[$i] : $ports[0]), 1];
}
$this->handler->addServers($servers);
if('' != $this->config['username']){
if ('' != $this->config['username']) {
$this->handler->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
$this->handler->setSaslAuthData($this->config['username'], $this->config['password']);
$this->handler->setSaslAuthData($this->config['username'], $this->config['password']);
}
return true;
}