The PHP client library supports a number of global options that
can be configured using the setOption()
method. The supported options are configured by using one of the
constnats in
Table 4.2, “Client Library Options”.
Table 4.2. Client Library Options
| Option | Description | ||
|---|---|---|---|
Couchbase::OPT_SERIALIZER | Specifies the serializer to be used when objects are stored. | ||
Couchbase::OPT_COMPRESSION | Specifies the compression to be used when storing large documents. | ||
Couchbase::OPT_PREFIX_KEY | Specifies the prefix key to be added to all stored document IDs. Can be used to create your own namespace within a given bucket. |
The serializer controls how objects are translated into the bytes stored as the document within Couchbase. For example, to configure the serializer to convert objects to JSON documents:
$couchbase->setOption(OPT_SERIALIZER, SERIALIZER_JSON);Using the serializer option employs the flags against objects stored within Couchbase to identify the serialization type. When reading or updating objects from other languages care should be taken to ensure that the flag values are retained to ensure compatibility. Alternatively, you can manually serialize/deserilize data which will not update the flags value.
| API Call | $object->setOption($option, $mixed) | ||
| Asynchronous | no | ||
| Description | Specify an option | ||
| Returns | boolean (
Boolean (true/false)
) | ||
| Arguments | |||
int $option | Option controlling connection or server behaviour | ||
scalar $mixed | Option value (constant, number, or string) | ||
The list of supported constants and behaviour are described in
Table 4.3, “Serializer Constants for OPT_SERIALIZER”.
Table 4.3. Serializer Constants for OPT_SERIALIZER
| Value | Value Description |
|---|---|
Couchbase::SERIALIZER_PHP | Serialize to/from a PHP object string |
Couchbase::SERIALIZER_JSON | Serialize objects to a JSON structure |
Couchbase::SERIALIZER_JSON_ARRAY | Serialize objects to an array of JSON structures |
Documents can be optionally compressed automatically as they are
stored into the database. The compression of these objects is
configured using the OPT_COMPRESSION option to
the setOption() function. For example:
$couchbase->setOption(Couchbase::OPT_COMPRESSION, Couchbase::COMPRESSION_ZLIB);
The list of supported constants and behaviour are described in
Table 4.4, “Serializer Constants for OPT_COMPRESSION”.
Table 4.4. Serializer Constants for OPT_COMPRESSION
| Value | Value Description |
|---|---|
Couchbase::COMPRESSION_NONE | Don't compress objects |
Couchbase::COMPRESSION_FASTLZ | Compress the document data using the Fast Lempel-Ziv compression. |
Couchbase::COMPRESSION_ZLIB | Compress the document data using the Zlib compression. |
You can also get the current value for a given option using the
getOption() function:
| API Call | $object->getOption($option) | ||
| Asynchronous | no | ||
| Description | Retrieve an option | ||
| Returns | scalar (
Binary object
) | ||
| Arguments | |||
int $option | Option controlling connection or server behaviour | ||