Let’s start with a list of the differences.
This list shows the differences between the ext/memcached and the ext/couchbase APIs.
The constructor for ext/couchbase takes a string identifying one of the cluster nodes. From there ext/couchbase figures out all the other nodes in a cluster automatically, whereas in ext/memcached you'd have to use multiple calls to the addServer() method, that doesn't exist in ext/couchbase.
ext/memcached's $persistent_id parameter allows you to tie specific instances of Memcached to persistent connections. In ext/couchbase connections are persistent by default and you can turn them off with the second optional parameter to __construct() and setting it to false
Note that calling new Couchbase($url) will make a REST call to Couchbase Server to determine the cluster topology. This is a relatively expensive call and that's the reason why we use persistent connections by default, so that this call doesn't have to be made more often then necessary, and most importantly not on every user-request.
That means, if you have any code that calls new Memcached(); in a tight loop, you want to move the call to new Couchbase(); to outside of that loop. If you compare performance between ext/memcached and ext/couchbase and find ext/couchbase to run at 1/2 the speed of ext/memcached, look for places where new Couchbase(); is called in a loop or otherwise repeatedly.
With ext/couchbase you no langer have to manually manage multiple memcached instances. All methods that are related to that use case aren’t supported by ext/couchbase.
append()'s signature in ext/couchbase is almost identical append() to ext/memcached. The only difference is two optional arguments: int $expiration and float $cas_token. $expliration lets you updated the expiration time for a key and $cas_token allows you to make the append operation fail if they key's existing cas_token has changed.
append() keeps working like you expect it, but you get the new case functionality if you like to use that.
prepend()'s signature in ext/couchbase is almost identical prepend() to ext/memcached. The only difference is two optional arguments: int $expiration and float $cas_token. $expliration lets you updated the expiration time for a key and $cas_token allows you to make the prepend operation fail if they key's existing cas_token has changed.
prepend() keeps working like you expect it, but you get the new case functionality if you like to use that.
decrement() adds three more optional parameters.
bool create = false determines whether ext/couchbase should create the key if it doesn't exist. With this you can model cases where you want to avoid decrementing non-existent keys. The default is false, do not create non existent keys.
int $expiration = 0 lets you set a new expiration time for the key. The default is 0, do not expire.
int initial = 0 allows you to specify an initial value in case you set create = true. This allows you to start at an arbitrary value without the need for running extra operations.
decrement() will work like it does in ext/memcached, but you will be able to use more features with the optional arguments.
increment() adds three more optional parameters.
bool create = false determines whether ext/couchbase should create the key if it doesn't exist. With this you can model cases where you want to avoid incrementing non-existent keys. The default is false, do not create non existent keys.
int $expiration = 0 lets you set a new expiration time for the key. The default is 0, do not expire.
int initial = 0 allows you to specify an initial value in case you set create = true. This allows you to start at an arbitrary value without the need for running extra operations.
increment() will work like it does in ext/memcached, but you will be able to use more features with the optional arguments.
delete() changes the second optional argument from int $time to float $cas_token. Delete with a timeout isn't supported by Couchbase, we hence don't allow a timeout to be specified with a delete().
Instead delete() gains the opportunity to use a cas value, so you can avoid deleting a key with a changed cas value.
If you rely on delete() with a time, you need to rework that part of your application.
Both ext/memcached and ext/couchbase use a number of constants throughout the API. Most notably result codes and configuration options.
For many constants, you can just switch the Memcached:: (or MEMCACHED_) prefix to the Couchbase:: (or COUCHBASE_) prefix. The constants below are the exception to this rule.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles distribution of keys over a cluster automatically. For that reasons specifying a hash algorithm doesn't make much sense. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.
There is no equivalent for this constant in ext/couchbase. JSON support is always included.
There is no equivalent for this constant in ext/couchbase.
The ext/couchbase equivalent of this constant are Couchbase::SUCCESS and COUCHBASE_SUCCESS respectively.
The ext/couchbase equivalent of this constant are Couchbase::ERROR and COUCHBASE_ERROR respectively.
The ext/couchbase equivalent of this constant are Couchbase::UNKNOWN_HOST and COUCHBASE_UNKNOWN_HOST respectively.
The ext/couchbase equivalent of this constant are Couchbase::PROTOCOL_ERROR and COUCHBASE_PROTOCOL_ERROR respectively.
The ext/couchbase equivalent of this constant are Couchbase::NETWORK_ERROR and COUCHBASE_NETWORK_ERROR respectively.
The ext/couchbase equivalent of this constant are Couchbase::KEY_EEXISTS and COUCHBASE_KEY_EEXISTS respectively.
The ext/couchbase equivalent of this constant are Couchbase::NOT_STORED and COUCHBASE_NOT_STORED respectively.
The ext/couchbase equivalent of this constant are Couchbase::KEY_ENOENT and COUCHBASE_KEY_ENOENT respectively.
The ext/couchbase equivalent of this constant are Couchbase::PROTOCOL_ERROR and COUCHBASE_PROTOCOL_ERROR respectively.
There is no equivalent of this constant in ext/couchbase.
The ext/couchbase equivalent of this constant are Couchbase::NETWORK_ERROR and COUCHBASE_NETWORK_ERROR respectively.