Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: PHP 1.0
Community Wiki and Resources
Wiki: PHP Client Library
PHP Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
3.1 Migrating from ext/memcached
Chapter Sections
Chapters

3.1.1. The Differences

3.1.1.1. Extension Methods
3.1.1.2. Extension Constants

Let’s start with a list of the differences.

3.1.1.1. Extension Methods

This list shows the differences between the ext/memcached and the ext/couchbase APIs.

3.1.1.1.1. __construct([string $cluster_url = http://default:@localhost:8091/default[, $persistent = true]])

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

3.1.1.1.1.1. Performance Considerations

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.

3.1.1.1.2. addByKey(), setByKey(), replaceByKey(), getByKey(), deleteByKey(), appendByKey(), prependByKey(), getDelayedByKey(), setMultiByKey(), getMultiByKey(), addServer(), addServers(), getServerbyKey(), getServerList()

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.

3.1.1.1.3. append($key, $value, [int $expiration[, float $cas_token]])

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.

3.1.1.1.4. prepend($key, $value, [int $expiration[, float $cas_token]])

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.

3.1.1.1.5. decrement(string $key[, int $offset = 1[, bool $create = false[, int $expiration = 0[, int $initial = 0]]]])

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.

3.1.1.1.6. increment(string $key[, int $offset = -1[, bool $create = false[, int $expiration = 0[, int $initial = 0]]]])

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.

3.1.1.1.7. delete(string $key[, float $cas_token])

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.

3.1.1.1.8. flush()

Like delete(), flush() doesn't support flushing after a timeout.

If you rely on flush() with a time, you need to rework that part of your application.

3.1.1.2. Extension Constants

3.1.1.2.1. Memcached::OPT_HASH
3.1.1.2.2. Memcached::HASH_DEFAULT
3.1.1.2.3. Memcached::HASH_MD5
3.1.1.2.4. Memcached::HASH_CRC
3.1.1.2.5. Memcached::HASH_FNV1_64
3.1.1.2.6. Memcached::HASH_FNV1A_64
3.1.1.2.7. Memcached::HASH_FNV1_32
3.1.1.2.8. Memcached::HASH_FNV1A_32
3.1.1.2.9. Memcached::HASH_HSIEH
3.1.1.2.10. Memcached::HASH_MURMUR
3.1.1.2.11. Memcached::OPT_DISTRIBUTION
3.1.1.2.12. Memcached::DISTRIBUTION_MODULA
3.1.1.2.13. Memcached::DISTRIBUTION_CONSISTENT
3.1.1.2.14. Memcached::OPT_LIBKETAMA_COMPATIBLE
3.1.1.2.15. Memcached::OPT_BUFFER_WRITES
3.1.1.2.16. Memcached::OPT_BINARY_PROTOCOL
3.1.1.2.17. Memcached::OPT_NO_BLOCK
3.1.1.2.18. Memcached::OPT_TCP_NODELAY
3.1.1.2.19. Memcached::OPT_SOCKET_SEND_SIZE
3.1.1.2.20. Memcached::OPT_SOCKET_RECV_SIZE
3.1.1.2.21. Memcached::OPT_CONNECT_TIMEOUT
3.1.1.2.22. Memcached::OPT_RETRY_TIMEOUT
3.1.1.2.23. Memcached::OPT_SEND_TIMEOUT
3.1.1.2.24. Memcached::OPT_RECV_TIMEOUT
3.1.1.2.25. Memcached::OPT_POLL_TIMEOUT
3.1.1.2.26. Memcached::OPT_CACHE_LOOKUPS
3.1.1.2.27. Memcached::OPT_SERVER_FAILURE_LIMIT
3.1.1.2.28. Memcached::HAVE_IGBINARY
3.1.1.2.29. Memcached::HAVE_JSON
3.1.1.2.30. Memcached::GET_PRESERVE_ORDER
3.1.1.2.31. Memcached::RES_SUCCESS
3.1.1.2.32. Memcached::RES_FAILURE
3.1.1.2.33. Memcached::RES_HOST_LOOKUP_FAILURE
3.1.1.2.34. Memcached::RES_PROTOCOL_ERROR
3.1.1.2.35. Memcached::RES_CLIENT_ERROR
3.1.1.2.36. Memcached::RES_SERVER_ERROR
3.1.1.2.37. Memcached::RES_WRITE_FAILURE
3.1.1.2.38. Memcached::RES_DATA_EXISTS
3.1.1.2.39. Memcached::RES_NOTSTORED
3.1.1.2.40. Memcached::RES_NOTFOUND
3.1.1.2.41. Memcached::RES_PARTIAL_READ
3.1.1.2.42. Memcached::RES_SOME_ERRORS
3.1.1.2.43. Memcached::RES_NO_SERVERS
3.1.1.2.44. Memcached::RES_END
3.1.1.2.45. Memcached::RES_BAD_KEY_PROVIDED
3.1.1.2.46. Memcached::RES_CONNECTION_SOCKET_CREATE_FAILURE
3.1.1.2.47. Memcached::RES_PAYLOAD_FAILURE

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.

3.1.1.2.1. Memcached::OPT_HASH

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.

3.1.1.2.2. Memcached::HASH_DEFAULT

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.

3.1.1.2.3. Memcached::HASH_MD5

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.

3.1.1.2.4. Memcached::HASH_CRC

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.

3.1.1.2.5. Memcached::HASH_FNV1_64

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.

3.1.1.2.6. Memcached::HASH_FNV1A_64

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.

3.1.1.2.7. Memcached::HASH_FNV1_32

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.

3.1.1.2.8. Memcached::HASH_FNV1A_32

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.

3.1.1.2.9. Memcached::HASH_HSIEH

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.

3.1.1.2.10. Memcached::HASH_MURMUR

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.

3.1.1.2.11. Memcached::OPT_DISTRIBUTION

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.

3.1.1.2.12. Memcached::DISTRIBUTION_MODULA

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.

3.1.1.2.13. Memcached::DISTRIBUTION_CONSISTENT

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.

3.1.1.2.14. Memcached::OPT_LIBKETAMA_COMPATIBLE

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.

3.1.1.2.15. Memcached::OPT_BUFFER_WRITES

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.16. Memcached::OPT_BINARY_PROTOCOL

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.17. Memcached::OPT_NO_BLOCK

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.18. Memcached::OPT_TCP_NODELAY

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.19. Memcached::OPT_SOCKET_SEND_SIZE

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.20. Memcached::OPT_SOCKET_RECV_SIZE

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.21. Memcached::OPT_CONNECT_TIMEOUT

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.22. Memcached::OPT_RETRY_TIMEOUT

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.23. Memcached::OPT_SEND_TIMEOUT

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.24. Memcached::OPT_RECV_TIMEOUT

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.25. Memcached::OPT_POLL_TIMEOUT

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.26. Memcached::OPT_CACHE_LOOKUPS

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.27. Memcached::OPT_SERVER_FAILURE_LIMIT

ext/couchbase handles low-level network settings transparently. There is no equivalent for this constant in ext/couchbase.

3.1.1.2.28. Memcached::HAVE_IGBINARY

There is no equivalent for this constant in ext/couchbase.

3.1.1.2.29. Memcached::HAVE_JSON

There is no equivalent for this constant in ext/couchbase. JSON support is always included.

3.1.1.2.30. Memcached::GET_PRESERVE_ORDER

There is no equivalent for this constant in ext/couchbase.

3.1.1.2.31. Memcached::RES_SUCCESS

The ext/couchbase equivalent of this constant are Couchbase::SUCCESS and COUCHBASE_SUCCESS respectively.

3.1.1.2.32. Memcached::RES_FAILURE

The ext/couchbase equivalent of this constant are Couchbase::ERROR and COUCHBASE_ERROR respectively.

3.1.1.2.33. Memcached::RES_HOST_LOOKUP_FAILURE

The ext/couchbase equivalent of this constant are Couchbase::UNKNOWN_HOST and COUCHBASE_UNKNOWN_HOST respectively.

3.1.1.2.34. Memcached::RES_PROTOCOL_ERROR

The ext/couchbase equivalent of this constant are Couchbase::PROTOCOL_ERROR and COUCHBASE_PROTOCOL_ERROR respectively.

3.1.1.2.35. Memcached::RES_CLIENT_ERROR

There is no equivalent of this constant in ext/couchbase.

3.1.1.2.36. Memcached::RES_SERVER_ERROR

There is no equivalent of this constant in ext/couchbase.

3.1.1.2.37. Memcached::RES_WRITE_FAILURE

The ext/couchbase equivalent of this constant are Couchbase::NETWORK_ERROR and COUCHBASE_NETWORK_ERROR respectively.

3.1.1.2.38. Memcached::RES_DATA_EXISTS

The ext/couchbase equivalent of this constant are Couchbase::KEY_EEXISTS and COUCHBASE_KEY_EEXISTS respectively.

3.1.1.2.39. Memcached::RES_NOTSTORED

The ext/couchbase equivalent of this constant are Couchbase::NOT_STORED and COUCHBASE_NOT_STORED respectively.

3.1.1.2.40. Memcached::RES_NOTFOUND

The ext/couchbase equivalent of this constant are Couchbase::KEY_ENOENT and COUCHBASE_KEY_ENOENT respectively.

3.1.1.2.41. Memcached::RES_PARTIAL_READ

The ext/couchbase equivalent of this constant are Couchbase::PROTOCOL_ERROR and COUCHBASE_PROTOCOL_ERROR respectively.

3.1.1.2.42. Memcached::RES_SOME_ERRORS

There is no equivalent of this constant in ext/couchbase.

3.1.1.2.43. Memcached::RES_NO_SERVERS

There is no equivalent of this constant in ext/couchbase.

3.1.1.2.44. Memcached::RES_END

There is no equivalent of this constant in ext/couchbase.

3.1.1.2.45. Memcached::RES_BAD_KEY_PROVIDED

There is no equivalent of this constant in ext/couchbase.

3.1.1.2.46. Memcached::RES_CONNECTION_SOCKET_CREATE_FAILURE

The ext/couchbase equivalent of this constant are Couchbase::NETWORK_ERROR and COUCHBASE_NETWORK_ERROR respectively.

3.1.1.2.47. Memcached::RES_PAYLOAD_FAILURE

The ext/couchbase equivalent of this constant are Couchbase::PROTOCOL_ERROR and COUCHBASE_PROTOCOL_ERROR respectively.