Welcome! Log In Create A New Profile

Advanced

ngx_lua now has (basic) subrequest support

agentzh
June 24, 2010 12:56AM
Hi, guys!

Last night's ngx_lua hackathon has been proven extremely fruitful.
chaoslawful and I didn't stop coding until midnight, and successfully
finished the first draft of the most tricky bit in ngx_lua, that is,
transparent non-blocking IO interface (or nginx subrequest interface)
on the Lua land.

The following test case is now passing:

  location /other {
      echo "hello, world";
  }

  # transparent non-blocking I/O in Lua
  location /lua {
      content_by_lua '
          local res = ngx.location.capture("/other")
          if res.status == 200 then
              ngx.echo(res.body)
          end';
  }

And on the client side:

   $ curl 'http://localhost/lua'
   hello, world

In the /other location, we can actually have drizzle_pass,
postgres_pass, memcached_pass,  proxy_pass, or any other content
handler configuration.

Here's a more amusing example to do "recursive subrequest":

 location /recur {
       content_by_lua '
           local num = tonumber(ngx.var.arg_num) or 0
           ngx.echo("num is: ", num, "\\n")

           if num > 0 then
               res = ngx.location.capture("/recur?num=" .. tostring(num - 1))
               ngx.echo("status=", res.status, " ")
               ngx.echo("body=", res.body)
           else
               ngx.echo("end\\n")
           end
           ';
   }

Here's the output on the client side:

    $ curl 'http://localhost/recur?num=3'
    num is: 3
    status=200 body=num is: 2
    status=200 body=num is: 1
    status=200 body=num is: 0
    end

You can checkout the git HEAD of ngx_lua to try out the examples above yourself:

http://github.com/chaoslawful/lua-nginx-module

So...time to replace our PHP code in the business with nginx.conf + Lua scripts!

We'd make the first public release of ngx_lua when its implementation
and API become solid enough ;)

Enjoy!
-agentzh

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

ngx_lua now has (basic) subrequest support

agentzh 3695 June 24, 2010 12:56AM

Re: ngx_lua now has (basic) subrequest support

Peter Leonov 1050 June 24, 2010 03:36AM

Re: ngx_lua now has (basic) subrequest support

agentzh 1209 June 24, 2010 06:24AM

Re: ngx_lua now has (basic) subrequest support

Akins, Brian 1128 June 25, 2010 11:44AM

Re: ngx_lua now has (basic) subrequest support

Boris Dolgov 1329 June 25, 2010 11:50AM

Re: ngx_lua now has (basic) subrequest support

agentzh 1140 June 26, 2010 01:00AM

Re: ngx_lua now has (basic) subrequest support

Akins, Brian 1039 June 26, 2010 09:02AM

Re: ngx_lua now has (basic) subrequest support

agentzh 1105 June 27, 2010 10:34PM

Re: ngx_lua now has (basic) subrequest support

Akins, Brian 1325 June 28, 2010 05:46PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 264
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready