I am using Couchbase PHP Extension to connect to Couchbase and implementing a feature that can detect if Couchbase is not responding and failover to MySQL. However, I can't figure out how to detect if Couchbase is down, I cannot find anything in their documentation for that.
Following is the code I have:
$cb = new Couchbase("$host:$port", $admin, $password, $bucket);
if (!$cb) {
throw Exception('Cannot connect to couchbase!');
}
Any help will be much appreciated.
I would recommend counting errors up to a threshold and then consider the connection 'down' and try to rebuild it.
Note that part of the reason it's difficult to determine 'down' is that Couchbase, by design, would rarely completely fail and even when failed nodes do occur, failover is triggered either automatically or manually bringing that connection object back online. It's different in this regard than connections to other databases.
I run into the same question, and solved it this way: