I have a php script that writes the whole page output (using output
buffering and PECL memcache module) to memcache using keys such as:
$host$request_uri
<?php
function memcache_ob($output) {
$time_start = microtime();
$cache_ttl = 300;
$key = trim($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211);
if ($cached = $memcache->get($key))
return str_replace('', "<!-- From memcache in ". round(microtime() -
$time_start, 4) . " (" . date('r') . ") -->\n", $cached);
$output = str_replace('', "<!-- Generated on " . date('r') . " / key:
"
. $key . " -->\n", $output);
$memcache->set($key, $output, false, $cache_ttl);
return $output;
}
ob_start('memcache_ob');
?>
In nginx, I have the following:
location ~ \.php$ {
set $memcached_key $host$request_uri;
memcached_pass 127.0.0.1:11211;
default_type text/html;
error_page 404 502 504 405 = @cache_miss;
}
location @cache_miss {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
The problem is that I’m getting garbled text returned by nginx, which
looks like this:
x�å\{sŪ¶²’;�¹ße;�=5õ
��meŅ�įȦta^�Ųź!+Øąōćė/�~žCżĖONķ�ę�ݼžā�ņļžõѶ�óóēW?æ��}2r°ńÆLó³;d^"ŲÉ+ÖłµwōÕg8īšWÓ$'�õ�C¦8ą�Xn¦rĪL�£ĖŽ��±×B8w)gy*�÷Ķ�Ą£Ü¾\ßīUG¢x�Ī�Ł�@5šgāǽb®c¦&h:1„ŖG�D�(Ź�ōūÉæC£w
a0źĶūæN<ŖpU�š{�)¤®1�+�z ¢Č`ŹžĮeŠÄ^r�ąB
P%ŖDų�®z�M�»��;§;ģ�
�RÆ:Ķ#0Ł>X�ĻšÉÄ'ž�2ŽŁ¹l�Qō³ÜP�¦��Ŗūlę��z�ś/fRÄ`ŪBī3;�I
+�Č�|Įč�éLØ”£�ē®!rź�c0’~�a�N
Ģõd5°³®Äė
×l7×�$�Ća'r
Posted at Nginx Forum:
kaspars
February 15, 2011, 4:40pm
2
Forgot to mention that I’m using Nginx 0.8.54.
Posted at Nginx Forum:
kaspars
February 15, 2011, 5:27pm
3
Hello!
On Tue, Feb 15, 2011 at 10:36:02AM -0500, kaspars wrote:
I have a php script that writes the whole page output (using output
buffering and PECL memcache module) to memcache using keys such as:
$host$request_uri
[…]
The problem is that I’m getting garbled text returned by nginx, which
looks like this:
x�å{sŪ¶²’;�¹ße;�=5õ
Looks like your client stores compressed data in memcached. Check
your client documentation to find out how to switch it off.
Maxim D.
kaspars
February 15, 2011, 7:53pm
4
On 2/15/11 1:38 PM, kaspars wrote:
Looks like your client stores compressed data in memcached. Check
your client documentation to find out how to switch it off.
I already did that – I’m sure it does not compress data.
I just noticed that the problem occurs only for pages with a lot of HTML
(6KB), while smaller pages (3KB) are rendered fine. This is nowhere
close to the 1MB limit of memcache. For this page
http://konstruktors.com/ everything is OK, while this
Blog about WordPress, Electronics and Software Products — Kaspars Dambis returns the garbled string.
This page renders normally in current Mac versions of Firefox, Opera,
and Safari for me.
nginx Info Page
–
Jim O.
kaspars
February 15, 2011, 7:53pm
5
On 15.02.2011 19:38, kaspars wrote:
I’ll try a different PHP memcache library, but I really doubt that it
will have any effect.
Hello,
one year ago i had a similar issue, i switched back to an older php pecl
memcache extension and
it solved my problem.
kaspars
February 15, 2011, 7:40pm
6
Looks like your client stores compressed data in memcached. Check
your client documentation to find out how to switch it off.
I already did that – I’m sure it does not compress data.
I just noticed that the problem occurs only for pages with a lot of HTML
(6KB), while smaller pages (3KB) are rendered fine. This is nowhere
close to the 1MB limit of memcache. For this page
http://konstruktors.com/ everything is OK, while this
Blog about WordPress, Electronics and Software Products — Kaspars Dambis returns the garbled string.
I’ll try a different PHP memcache library, but I really doubt that it
will have any effect.
Posted at Nginx Forum:
kaspars
February 15, 2011, 8:06pm
7
Jim O. Wrote:
http://konstruktors.com/ everything is OK, while
this
Blog about WordPress, Electronics and Software Products — Kaspars Dambis returns the
garbled string.
This page renders normally in current Mac versions
of Firefox, Opera,
and Safari for me.
No problem viewing the page either here as well.
Posted at Nginx Forum:
kaspars
February 15, 2011, 10:08pm
8
one year ago i had a similar issue, i switched back to an older php
pecl
memcache extension and
it solved my problem.
That’s interesting, Alexander. I’ll give it a try.
And thanks to Jim and Dayo for reporting on the output of the page.
Posted at Nginx Forum:
kaspars
February 16, 2011, 11:28am
9
The problem was indeed caused by the php5-memcache PECL package I had
installed from dotdeb (I guess php5-memcache_5.3.5-0.dotdeb.0_i386.deb).
So I compiled a fresh one (from http://pecl.php.net/package/memcache )
using the official PECL installer and everything is perfect now.
Thanks to everyone for helping me figure this out.
Kaspars
Posted at Nginx Forum: