Request inside a timer
António P. P. Almeida
appa at perusio.net
Fri Feb 10 23:35:45 UTC 2012
On 10 Fev 2012 23h04 WET, 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/
I think it can. Since right now you can create sockets right within
the config. Therefore making the request from within is possible. As
is processing the response and updating the config based on the values
obtained.
http://wiki.nginx.org/HttpLuaModule#ngx.socket.tcp
What does your embedded Perl offer that you cannot accomplish with
this?
--- appa
More information about the nginx-devel
mailing list