Php libcouchbase连接错误
Couchbase一直抱怨我与Couchbase没有连接:Php libcouchbase连接错误,php,couchbase,Php,Couchbase,Couchbase一直抱怨我与Couchbase没有连接: 2013-10-28T11:15:46.580320-07:00 hoot77 apache2[30455]: PHP Warning: There is no active connection to couchbase in /ebs1/www/src/core/components/In/Couchbase/Bucket.php on line 112 下面是一段试图运行的代码,它是一个简单的集合 */ public
2013-10-28T11:15:46.580320-07:00 hoot77 apache2[30455]: PHP Warning: There is no active connection to couchbase in /ebs1/www/src/core/components/In/Couchbase/Bucket.php on line 112
下面是一段试图运行的代码,它是一个简单的集合
*/
public function set($key, $doc, $try = 0) {
// Make sure designDoc and dataView are set
if(empty($this->designDoc) && empty($this->dataView)) {
throw new In_Exception('Missing Design Doc and/or View name for Couchbase', 400);
}
try {
$results = $this->cb->set($key, $doc);
} catch(CouchbaseLibcouchbaseException $e) {
// Connection not active, try to rebuild connection and query again
// Log stats on exception
Statsd::increment("web.Couchbase.Exception.LibCouchbaseException.{$this->instanceKey}");
Logger::error("LibCouchbaseException on {$this->instanceKey}: {$e->getMessage()}");
// Try to reconnect and query up to twice
$try++;
if($try <= 2) {
$this->rebuildConnection();
return $this->set($key, $doc, $try);
} else {
// Fail if we've already tried twice
throw new In_Exception('Could not connect to Couchbase', 500);
}
} catch(CouchbaseException $e) {
// Catch general exception, try to determine cause
// Log stats on exception
Statsd::increment("web.Couchbase.Exception.CouchbaseException.{$this->instanceKey}");
Logger::error("CouchbaseException on {$this->instanceKey}: {$e->getMessage()}");
// Throw exception if design document or view not found
if($this->getExceptionCode($e->getMessage()) == 404) {
throw new In_Exception('Design Document, or View not found in Couchbase', 404);
} else {
throw new In_Exception('Error with Couchbase, try again.', 500);
}
}
// Success, return results
Statsd::increment("web.couchbase.{$this->instanceKey}.success");
return $results;
}
您可以看到,我的快速解决方案是在出现故障时尝试重新连接两次,但这似乎没有任何帮助,错误仍然大量存在
它实际上没有捕获异常并一致地报告它们,这很烦人,因为PHP将这些作为警告而不是异常抛出
如果您对如何解决这个问题有任何建议,请告诉我,我们将不胜感激。谢谢 在哪里实例化couchbase(
$this->cb
)对象?你确定它会实例化吗?谢谢你的回答,连接肯定是在构造函数中实例化的,即使我使用Couchbase类本身(不是我的抽象),也会发生同样的错误。这似乎发生在长时间运行的进程上?这是目前我能说的最好的了。可能是持久连接的问题
$results = $this->cb->set($key, $doc);