Couchbase PHP SDK:如何检测Couchbase连接失败? [英] Couchbase PHP SDK: How to detect couchbase connection failure?

查看:43
本文介绍了Couchbase PHP SDK:如何检测Couchbase连接失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Couchbase PHP扩展连接到Couchbase,并实现了一项功能,该功能可以检测Couchbase是否没有响应并故障转移到MySQL。但是,我无法弄清楚如何检测Couchbase是否关闭,因此无法在其文档中找到任何内容。

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.

以下是我的代码:

$cb = new Couchbase("$host:$port", $admin, $password, $bucket);
if (!$cb) {
    throw Exception('Cannot connect to couchbase!');        
}

任何帮助将不胜感激。

推荐答案

我遇到了同样的问题,并通过以下方式解决了该问题:

I run into the same question, and solved it this way:

$cb = @new Couchbase($host.":".$port,$username,$password,$bucket,$persistent);
if($cb->getResultCode() != COUCHBASE_SUCCESS){ 
    throw Exception('Cannot connect to couchbase!'); 
} 

这篇关于Couchbase PHP SDK:如何检测Couchbase连接失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆