The community forums are in BETA and closed to the public.

Sending GZIP Compressed JSON Messages Over HTTP Streaming and WebSockets

Sending GZIP Compressed JSON Messages Over HTTP Streaming and WebSockets

PubNub PHP SDK supports publishing your JSON payloads with GZIP Compression enabled for sending data over PubNub Data Stream Channels. Simply set the "compress" : true flag to true and gzip payloads will be sent instead of uncompressed text.

require_once './Pubnub.php';

$conf = [
    'pubnub.channel'    => 'my_channel',
    'pubnub.pub_key'    => 'demo',
    'pubnub.sub_key'    => 'demo',
];

$msg        = "test";
$compress   = true;
$pubnub     = new Pubnub(
    $conf['pubnub.pub_key'], 
    $conf['pubnub.sub_key'], 
    $compress ## Default to Compression Enabled
);

## PUBLISH WITH COMPRESSION ON-DEMAND
$result = $pubnub->publish([
    'channel'   => $conf['pubnub.channel'],
    'message'   => [ 'test message' => $msg ],
    'compress'  => $compress ## COMPRESSION ENABLED ON-DEMAND
]);

I don't know if this is documented (I couldn't find), but you can also subscribe to gzipped streams.

Yes! You are correct. Content-Encoding: gzip Include the Content-Encoding header with gzip as the value.


Comments to this discussion are now closed!