Set generated PHP output to Memcached server by Nginx transparently

Hi,

I have set up for NginxHttpMemcachedModule and it works great reading
output that I have set to Memcached server through my OWN PHP code. But
that means I have to modify my PHP code to make it happens and sometimes
it is not easy if the code is third party. I really think it would be
more beneficial if the NginxHttpMemcachedModule could set the generated
PHP output into Memcached server. By doing so, I don’t have to modify
PHP code to make it happen and it offers much better maintenance, using
Nginx server as the Memcache (cluster) Proxy.

Basically I need to be able to read PHP output from Memcached server:

  1. If there is PHP output in the Memcached server given $uri, use it
  2. If not, use fallback to the fastcgi or PHP-FPM
  3. The generated PHP output of step 2 is set to the Memcached server BY
    NGINX TRANSPARENTLY (no PHP code change but just Nginx configuration) to
    the Memcached server so it can be read next time on step 1.

I notice that there is another module call NginxHttpMemcModule. It seems
that it could do the trick but I am not sure by looking at the
configuration example in the wiki.

Could someone provide some insight on this issue?

Thanks!
– Jin Kuang

Posted at Nginx Forum:

This is like the Holy Grail. See my similar request here
Please Help With Memcached Setup.

However, the answer I got was on the cryptic side with the only thing I
could make out being it is not a good idea with proxy which I use as at
yet so I gave up.

Posted at Nginx Forum:

However, the answer I got was on the cryptic side with the only thing I
could make out being it is not a good idea with proxy which I use as at
yet so I gave up.

Cryptic?

The module GitHub - openresty/srcache-nginx-module: Transparent subrequest-based caching layout for arbitrary nginx locations. has the
ability to
“cache” - store subrequest response in memcached backend (combined with
memc
or any other module).

rr

Dayo, thank you for the response. It seem that is what I am looking
for. I am going to try it out and see if it works.

Given the fact that this is still on the “bleeding edge” side of Nginx
usage, I am thinking it might be better off if I will just use a
“middleware” PHP to handle the update to the memcached server.

  1. If there is PHP output in the Memcached server cluster given $uri,
    use it (with header stuff set)

  2. If not, REWRITE the URL for
    http://mysite.com/memcached_update.php?location=the_original_url

This memcached_update.php will open up a output buffer, perform a url
get for the content of the original url, store the buffered content in
memcached server (unfortunately that means this PHP will need to perform
memcached server look up and cluster management in a clustered memcached
environment) and return the content

  1. Next time the same location is requested, we should have the content
    available in the memcached server cluster.

This should not have impact on the original application as the
“middleware” PHP is generic. But still it is a messy hack. It is not
“pretty”

I really hope NginxHttpMemcachedModule or NginxHttpMemcModule should
bundle this critical capability in the modules directly. It seems so
obviouos this job belongs to these two modules.

Thanks
– Jin Kuang

Posted at Nginx Forum: