Request inside a timer

Alexandr Gomoliako zzz at zzz.org.ua
Fri Feb 10 23:04:13 UTC 2012


On Sat, Feb 11, 2012 at 12:39 AM, António P. P. Almeida
<appa at perusio.net> wrote:
>> I would like to do a module which, at some interval, refresh part of
>> its configuration getting some values from a external service.  So I
>> need to make a GET independent of a user request.
>
> I suggest not doing a module, but instead making use of:
>
> http://wiki.nginx.org/HttpLuaModule
>
> It can do that and more, much more.

I don't think it can. But pretty easy with Nginx::Perl:

use Nginx;
use Nginx::HTTP;

sub init_worker {
    ...
    my $req = "GET / HTTP/1.1" . "\x0d\x0a" . "Host: foobar" .
"\x0d\x0a\x0d\x0a" ;

    ngx_timer 0, 5, sub {
        ngx_http "1.2.3.4:80", $req, sub {
            my ($headers, $buf_ref) = @_;

            unless ($headers) {
                ngx_log_error $!, "error";
                return;
            }

            ngx_log_notice 0, "got $headers->{'_status'}";
            ...
        };
    };
}

http://zzzcpan.github.com/nginx-perl/



More information about the nginx-devel mailing list