Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: PHP 1.1
Community Wiki and Resources
Wiki: PHP Client Library
PHP Client Library
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
4 Connection Operations
Chapter Sections
Chapters

4.2. Setting Client Library Options

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

OptionDescription  
Couchbase::OPT_SERIALIZERSpecifies the serializer to be used when objects are stored.  
Couchbase::OPT_COMPRESSIONSpecifies the compression to be used when storing large documents.  
Couchbase::OPT_PREFIX_KEYSpecifies 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);

Note

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)
Asynchronousno
Description Specify an option
Returnsboolean ( 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

ValueValue Description
Couchbase::SERIALIZER_PHPSerialize to/from a PHP object string
Couchbase::SERIALIZER_JSONSerialize objects to a JSON structure
Couchbase::SERIALIZER_JSON_ARRAYSerialize 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

ValueValue Description
Couchbase::COMPRESSION_NONEDon't compress objects
Couchbase::COMPRESSION_FASTLZCompress the document data using the Fast Lempel-Ziv compression.
Couchbase::COMPRESSION_ZLIBCompress 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)
Asynchronousno
Description Retrieve an option
Returnsscalar ( Binary object )
Arguments 
int $option Option controlling connection or server behaviour
API Call$object->setTimeout($timeout)
Asynchronousno
Description Set the configured timeout value for operations
Returnsscalar; supported values:
 scalarCurrent timeout in microseconds 
Arguments 
scalar $timeout The operation timeout specified in microseconds
API Call$object->getTimeout()
Asynchronousno
Description Get the currently configured timeout value for operations
Returnsscalar ( The operation timeout specified in microseconds )
Arguments 
 None