Nginx and Memcache

Hi,

I have recently installed Nginx as a front facing server to communicate
with memcache. My problem is that the PHP code that writes into memcache
serializes the contents. I cannot turn off serialization but need to
figure out how to get the string content from memcache. The current
output from Nginx is of type application/octet-stream. Is there
something I missed?

Thank you.

Regards
Anil

Posted at Nginx Forum:

Hello!

On Fri, Oct 22, 2010 at 09:39:03AM -0400, midas wrote:

Hi,

I have recently installed Nginx as a front facing server to communicate
with memcache. My problem is that the PHP code that writes into memcache
serializes the contents. I cannot turn off serialization but need to
figure out how to get the string content from memcache. The current
output from Nginx is of type application/octet-stream. Is there
something I missed?

As memcached values doesn’t store/return any content type - nginx only
able to detect it based on request uri extension (i.e. the same
logic as for static files applies).

See details here:

http://wiki.nginx.org/HttpCoreModule#default_type
http://wiki.nginx.org/HttpCoreModule#types

E.g to make sure all replies from memcached are returned as
text/plain do something like this:

location /memcached/ {
    types {}
    default_type text/plain;
    memcached_pass ...
}

Maxim D.

Thanks Maxim

My problem is that the value coming from memcache is a php serialized
string content (byte-stream). I was able to change the content send from
nginx with your suggestion. But I still get errors since the response
contains invalid characters.

BTW is there a way to cache response from memcache in Nginx so that the
server does not have to keep going to memcache for data?

Regards
Anil

Posted at Nginx Forum:

Hello!

On Fri, Oct 22, 2010 at 03:24:56PM -0400, midas wrote:

My problem is that the value coming from memcache is a php serialized
string content (byte-stream). I was able to change the content send from
nginx with your suggestion. But I still get errors since the response
contains invalid characters.

You should put non-serialized data into memcached.

BTW is there a way to cache response from memcache in Nginx so that the
server does not have to keep going to memcache for data?

No. It’s presumed that memcached is fast enough to not require
additional caching.

Maxim D.

Thanks Maxim,

This helped a lot. I was able to dig into the code and remove
serialization.

Was thinking about file caching in Nginx. Is there a way to configure
file caching? I apologize for all the questions. Kinda new to Nginx.
I need the server to respond to a very high amount of traffic.

Regards
Anil

Posted at Nginx Forum:

Hi,

I finally have Nginx working with memcache and doing its job perfectly.
I have a question regarding the memcache_pass configuration. Is it
possible to have a pool of memcache servers instead of one memcache
server?

Regards
Anil

Posted at Nginx Forum:

Hello!

On Tue, Oct 26, 2010 at 11:38:41AM -0400, midas wrote:

Hi,

I finally have Nginx working with memcache and doing its job perfectly.
I have a question regarding the memcache_pass configuration. Is it
possible to have a pool of memcache servers instead of one memcache
server?

You are free to use defined upstream[1] in memcached_pass. By
default nginx will use round-robin though. Blancing methods
compatible with Cache::Memcached and other memcached client
libraries are available as third party modules[2][3].

[1] Module ngx_http_upstream_module
[2] Разработка мобильных приложений на заказ в Молдове
[3] Upstream Consistent Hash | NGINX

Maxim D.

Awesome! I had read about the upstream module. I was not sure if it
could be used along with memcache_pass.
Thanks Maxim.

On another topic altogether, is there an APC module for Nginx?

Regards
Anil

Posted at Nginx Forum: