PHP 2.0.3 Syntax question for Brett19


From IRC, Dave_R and mnbg_ said you were the guy to go to for PHP 2.0.3 questions.

I am looking for syntax examples for:

A) durability->replicate_to (how to implement waiting for single node replication)
B) Setting API timeout duration to then fail over to another node. How is failure detected to then migrate next node?
C) getFromReplica(string $id, array $options = array()) : mixed (What are the options?)



Hey md1,

A) Simply pass a replicate_to number greater to 0 to the options for any of the storage operations and internally the operation will not return until the specified durability requirements are met. Note that the operation may succeed, while the durability requirements do not, so you should inspect the errors.

B) Simply set your operation timeout, then perform your get operation. If the get operation fails due to a timeout, you can fall back to using getFromReplica to read the data from an alternate node. Keep in mind the data returned from a replica may be stale, and is immutable on a replica server.

C) index is the only accepted option which specifies the specific replica server to read your data from. 0 indicates the first replica server, 1 indicates the second replica server and -1 is a special case indicating to request the document from all replicas, and return the document from the server who answers first.

Cheers, Brett


Thanks for the quick response.

Can you add actual syntax examples to each response.

That is my problem, missing examples and syntax.

That is what the online documentation is missing, more examples instead of just the class header.

Hey md1,

Here is an example of using replicate_to on a storage operation.

$bucket->upsert('key', 'value', array('replicate_to'=>1));

And an example of falling back to getReplica when needed.

function getFromSomewhere($key) {
  try {
    return $bucket->get($key);
  } catch (CouchbaseException $e) {
    if ($e->code == COUCHBASE_ETIMEDOUT) {
      return $bucket->getFromReplica($key);
    throw $e

Cheers, Brett

That is a great message, thanks.