Checked server count before trying to close

Was throwing an error, probably should wrap it in a try/catch but better to suppress the action entirely
This commit is contained in:
Josh Sherman 2013-03-07 15:48:08 -05:00
parent 85e3119ed1
commit e02890b97a
2 changed files with 20 additions and 2 deletions

View file

@ -44,6 +44,14 @@ class Cache extends Object
*/
private $namespace = '';
/**
* Servers
*
* @access private
* @var integer
*/
private $servers = 0;
/**
* Connection resource to Memcached
*
@ -84,6 +92,7 @@ class Cache extends Object
$datasource = $this->config->datasources[$name];
$this->connection->addServer($datasource['hostname'], $datasource['port']);
$this->servers++;
if (isset($datasource['namespace']))
{
@ -106,7 +115,7 @@ class Cache extends Object
*/
public function __destruct()
{
if ($this->connection)
if ($this->servers)
{
$this->connection->close();
}

11
jar.php
View file

@ -623,6 +623,14 @@ class Cache extends Object
*/
private $namespace = '';
/**
* Servers
*
* @access private
* @var integer
*/
private $servers = 0;
/**
* Connection resource to Memcached
*
@ -663,6 +671,7 @@ class Cache extends Object
$datasource = $this->config->datasources[$name];
$this->connection->addServer($datasource['hostname'], $datasource['port']);
$this->servers++;
if (isset($datasource['namespace']))
{
@ -685,7 +694,7 @@ class Cache extends Object
*/
public function __destruct()
{
if ($this->connection)
if ($this->servers)
{
$this->connection->close();
}