Answer the question
In order to leave comments, you need to log in
Why is nginx throwing garbage from memcached?
Through php memcached I write data to memcached:
$this->memcached->setOptions([
\Memcached::OPT_COMPRESSION => true,
\Memcached::OPT_BINARY_PROTOCOL => true,
]);
$key = '...';
$value = '...';
$this->memcached->set($key, $value);
location ~ \.php$ {
set $memcached_key "...";
gunzip on;
memcached_gzip_flag 2;
memcached_pass unix:/run/memcached/memcached.socket;
error_page 404 405 = @php;
}
Answer the question
In order to leave comments, you need to log in
In short, with grief in half solved the problem.
The problem turned out to be, as I thought, in the wrong compression : php-memcached compresses data as deflate, and nginx only recognizes gzip and, by the way, the last one is right - gzip, unlike deflate, roughly speaking, "more unambiguous" and even works with the most buggy browsers.
I wrote to the developers of php-memcached with a suggestion to add gzip compression, but they, apparently, are conservatives and do not want to change anything (as I felt a catch when I looked at the date of the latest version ). The funny thing is that adding support for gzip there is as easy as shelling pears - work for 20 minutes maximum , sources are simpleeven for me, far from C. At first I thought to propose changes to them myself, but oh well ... The extension was demolished. I did it through sockets, as it turned out, working with memcached directly is not so difficult .
$key = 'key';
$flags = 1;
$expire = 0;
$value = gzencode('value', 6, FORCE_GZIP);
$length = strlen($value);
if (!fwrite($memcached, "set {$key} {$flags} {$expire} {$length}\r\n{$value}\r\n")) {
throw new Exception('Memcached write error.');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question