Request inside a timer
Peter Leonov
gojpeg at gmail.com
Fri Feb 17 19:30:29 UTC 2012
Well done by the way! :)
On 11.02.2012, at 3:04, Alexandr Gomoliako <zzz at zzz.org.ua> wrote:
> 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/
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
More information about the nginx-devel
mailing list