2011年2月15日星期二

Memcache and garbled text returned by Nginx

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

[code]
<?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');

?>
[/code]

In nginx, I have the following:

[code]
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;
}
[/code]

The problem is that I'm getting garbled text returned by nginx, which
looks like this:

[code]
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
[/code]

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,175470,175470#msg-175470


_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx

没有评论:

发表评论