0

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 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;
}

它抱怨的行是:

$results = $this->cb->set($key, $doc);

您可以看到我的快速解决方案是尝试在失败时重新连接最多两次,但这似乎根本没有帮助,错误仍然大量存在。

它实际上也没有捕获异常并始终如一地报告它们,这很烦人,因为 PHP 将这些作为警告而不是异常抛出。

如果您对如何解决此问题有任何建议,请告诉我,我们将不胜感激。谢谢!

4

0 回答 0