In PHP I am doing something like:
$gzdata = gzencode(json_encode($data), 9);
$mc->set("latest", $gzdata);
So I pull my associative array from the DB, I turn it to JSON, Gzip it and store to memcache
In my Node.js I read the memcached entry and serve it (where client is memcache client)
client.get('latest', function(err, response) {
if (err) { console.log("GET", err.type ); }
else{
result.writeHead(200,{
"Content-Type": "application/json",
"content-encoding":"gzip"
});
result.end(response['latest']);
}
});
I am getting
Content Encoding Error
on the page
The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.
I cannot even check the headers in FB... any ideas what am I doing wrong?
Did you know that the Memcache client can already do compression for you?
$memcache_obj = new Memcache;
$memcache_obj->addServer('memcache_host', 11211);
$memcache_obj->setCompressThreshold(20000, 0.2);
This would compress values when larger than 20k with a minimum compression of 20%.
See also: Memcache::setCompressThreshold