I have a Perl code that use threads
and HTTP::Async
with multiple outbound IP addresses >>
use threads ( 'yield',
'exit' => 'threads_only',
'stack_size' => 2*16384 );
use strict;
use warnings;
no warnings 'threads';
use threads::shared;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Async;
...
my $async = HTTP::Async->new( ... );
...
foreach (@list) {
$thread = threads->create( sub {
local $SIG{KILL} = sub { threads->exit };
...
$ua->local_address($ip);
$request->url($url);
$async->add($request);
while ($response = $async->wait_for_next_response) {
...
}
}, $_);
}
...
I need to generate some basic application logs that would include url and outbound IP information.
How can I log HTTP::Async
communication?
You are not actually using LWP in that code, you are just loading it. Likewise from your code example it's not clear why you are using threads. HTTP::Async takes care of doing multiple HTTP requests "at once".
It doesn't look like HTTP::Async has any built-in debug mechanisms, but it'd be relatively straightforward to add a 'debug' flag in that module and some warn statements at the appropriate places if you need help seeing what it's doing. You could also add the debug code in your own code that's using HTTP::Async.