how can i use memcached_module

Liang Jin mywebadmin at gmail.com
Mon May 7 03:27:46 MSD 2007


Hi,

First of all, you need to configure Memcached daemon. In the config
file you showed, it is located at localhost:10000 .

So when a client visit your site, nginx will try this Memcached server
to fetch the key defined in $memcached_key.  If the client requests
domain1.com/path1/file1.php

This URL would be the key in Memcached cache, that stores the HTML
cache file for that page.

If nginx cannot find the key in the Memcached cache, it will return an
404 error, which in the config file will fallback to the backend
proxy.

The first time when a visitor views the page, it will always fallback
to the backend. At that time, you should add in your PHP code to store
the HTML page in the Memcached with the correct key. So the next time,
the page will be served by nginx using the contents in the Memcached
cache.

Does it make sense? For PHP memcached client, you can use the official
php-memcache module.

-Liang



On 5/6/07, 焦胜强 <jiaosq at mail.51.com> wrote:
> HI:
>     how can use the memcached_module in php?
>     can someone give a example?
> I can not understand this configfile:
> ...
>         upstream   backend {
>             server   localhost:80;
>         }
> ...
>         location /memcached/ {
>             internal;
>             ssi on;
>             set     $memuri $uri;
>             set     $memcached_key   "$memuri";
>             memcached_pass  localhost:10000;
>             error_page 404 =200 /memcached-miss$memuri;
>         }
> ...
>         location /memcached-miss/ {
>             internal;
>             ssi on;
>             rewrite   ^/memcached-miss/(.*)$  /$1 break;
>             proxy_set_header    Host             $host;
>             proxy_set_header    X-Real-IP        $remote_addr;
>             proxy_pass          http://backend;
>             proxy_redirect      off;
>         }
>


More information about the nginx mailing list