Couchbase Server 1.8 connection issue with PHP
Hi,
I am using Couchbase Server 1.8 community edition in 3 nodes. The auto fail over functionality is working properly when a server fails, But PHP client could not connect to the rest of the server nodes.
I am connecting to the cluster by using the following method
$cb_obj = new Couchbase("localhost", "Administrator", "password", "default");
Error shown when one of the node fails(localhost)
Warning: Couchbase::__construct(): Failed to connect libcouchbase to server: Network error in......
Please help.
Regards,
Siji
Hi again Siji,
do I guess correctly that your scenario is the following:
1. Set up a cluster on localhost and one or more other hosts.
2. Use new Couchbase("localhost", ...);
3. Make the localhost node fail.
4. new Couchbase("localhost, ...); fails.
If that is correct, we are working on a fix that allows you to specify multiple hosts at once in your PHP script. Really, we should have done so all along, but we only now got to it.
In the meantime you could do this:
<?php
// excuse any errors, I haven't run this, I'm just illustrating ;)
$hosts = array("localhost", "otherhost", "yetanotherhost");
foreach($hosts AS $host) {
$cb = @new Couchbase($host, ...);
if($cb) {
break;
}
}
if(!$cb) {
// throw error, no server available
}
Cheers
Jan
--
Hi Jan,
Thanks for your replay, Your guessing was correct, That was the exact problem we were facing. we already implemented one similar method and it seems working fine now.
We are looking out for the proper fix.
Regards,
Siji
Hi Siji
Next version of libcouchbase (and also all clients using it underneath) will have a patch which allows connection to use list of last known nodes from the cluster. This means that if your _initial_ connection was successful, you can be sure that, when the current node will fail, the connection will be still alive while at least one node in cluster is alive. There is an API (for upcoming version) to get current host and port https://github.com/couchbase/libcouchbase/blob/master/include/libcouchba... so Jan could expose it to php land.
So with next version code snippet will be totally valid (unlike with current, where the initial node still might fail later)
Hi Siji,
thanks for the report, I'm looking into this today :)
Cheers
Jan
--