I have a web server running nginx on http://192.168.x.x, and a perl module is installed using http://nginx.org/en/docs/http/ngx_http_perl_module.html
I need to do a GET request inside that module using LWP. This is what i have:
my $url = "http://192.168.x.x/app/test.php";
my $ua = LWP::UserAgent->new;
$ua->timeout(5); # muere a los 5 segundos sin respuesta.
$ua->default_header('Cookie' => "FOO=BAR;PATH=/");
my $resp = $ua->get($url);
if ($resp->is_success) {
my $message = $resp->decoded_content;
print STDERR "Received reply: $message\n";
} else {
print STDERR "HTTP GET error code: ", $resp->code, "\n";
print STDERR "HTTP GET error message: ", $resp->message, "\n";
};
Everytime i do that request i get error code 500 : read timeout. But if i use another server works just fine. The problem is when i use the same server where i run the script.
I think this is because nginx has only one worker thread. When you call your perl code inside nginx it blocks whole server. So one nginx can't process your blocking perl code and php handler at the same time. This is deadlock. You can try Nginx::HTTP which shouldn't block nginx while waiting http response. So, this will work, I think.