简体   繁体   English

如何在 Perl 中记录 HTTP::Async 通信?

[英]How can I log HTTP::Async communication in Perl?

I have a Perl code that use threads and HTTP::Async with multiple outbound IP addresses >>我有一个使用threads的 Perl 代码和HTTP::Async与多个出站 IP 地址 >>

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.我需要生成一些基本的应用程序日志,其中包括url出站 IP信息。

How can I log HTTP::Async communication?如何记录HTTP::Async通信?

You are not actually using LWP in that code, you are just loading it.您实际上并没有在该代码中使用LWP ,您只是在加载它。 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". HTTP::Async 负责“一次”执行多个 HTTP 请求。

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.它看起来不像HTTP::Async有任何内置的调试机制,但如果您需要帮助查看它是什么,那么在该模块中添加一个“调试”标志并在适当的位置添加一些警告语句会相对简单正在做。 You could also add the debug code in your own code that's using HTTP::Async.您还可以在自己使用 HTTP::Async 的代码中添加调试代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM