Data transfer compression between server and clients

Is there a specific way to enable data transfer compression from Couchbase server to PHP SDK clients?

I am guessing if it is available and already enabled by default, to reduce internal network usage and increase performances. I found this discussion (link) in which is mentioned that some clients have built-in data compresion. Does PHP SDK has this feature? How can it be enabled?

We actually use Couchbase server 4.1 community edition and PHP SDK 2.2.3.

Thank you

There are two kinds of compression in couchbase. First type is server-size, where all values on the server transparently compressed with snappy library. This type is not visible for SDK and SDKs cannot supply encoded value to the server so that it will skip its compression.

The second type is compression, built into SDK. This could be used to save traffic between client and the server. But this compression considered private to each of the SDKs and obviously cannot be used by the server (i.e. server sees compressed values as BLOBs, and FTS/N1QL/Views will not be able to index it). Different SDKs implement different types of compression, and some of them do not implement it at all. Compression is not enabled in PHP SDK by default, but you can enable it by configuring the transcoder. It supports FASTLZ and ZLIB compression. For example:

<?php
$cluster = new CouchbaseCluster("couchbase://localhost");
$COUCHBASE_DEFAULT_ENCOPTS["cmprtype"] = COUCHBASE_CMPRTYPE_FASTLZ;
$COUCHBASE_DEFAULT_ENCOPTS["cmprthresh"] = 20; // do not compress values less than 20 bytes
$COUCHBASE_DEFAULT_ENCOPTS["cmprfactor"] = 1.2; // do not use compression if value has shrunk less than 20%
$bucket = $cluster->openBucket("default");
$bucket->upsert("foo", ["large_property" => str_repeat('x', 40000)]);

FYI right now 2.2.3 release of php client has issue with deserializing compressed values, which has been fixed in https://issues.couchbase.com/browse/PCBC-439. As a workardound, you can copy decoder with the fix and override default one.

Very good, this could give us many benefits and increase app load time.

Thank you for the fix of the issue, I didn’t noticed this bug.