如何使Apache“睡眠”几秒钟

时间:2013-09-25 14:14:01

标签: perl apache

我希望我的服务器停止几秒,然后重新开始。 我正在尝试使用sleep(5)。 这会有帮助吗?

我尝试使用 Perl 脚本,其中包含:

if($mech=~ m/(Connection refused)/) {print "SLEEPING\n";sleep(5);redo;}

1 个答案:

答案 0 :(得分:0)

服务器托管网页。客户端连接到服务器。使用WWW :: Mechanize的Perl脚本是客户端

我怀疑您正在尝试执行以下操作:

my $retries = 3;
my $resp; # response goes here
while ( $retries-- > 0 ) {
    $resp = $ua->get( "http://www.google.com/" );
    if ( ! $resp->is_success ) {
        warn( "Failed to get webpage: " . $resp->status_line );
        sleep( 5 );
        next; # continue the while loop
    }

    last; # success!
}

if ( $retries == 0 ) {
    die( "Too many retries!" );
}

# old versions of LWP::UserAgent didn't have decoded_content()
my $content = $resp->can('decoded_content') ? 
    $resp->decoded_content : $resp->content;

print( $content );

<强>更新

以下是您在评论中提供的代码:

use WWW::Mechanize;
my $mech = new WWW::Mechanize;
eval {
    $mech->get($url);
}; 
if($@) { 
    print STDERR "Burst\n";
    print STDERR Dumper($mech);
    # my $var=$mech;
    # print STDERR "var $var\n";
    # if($mech=~ m/(Connection refused)/) 
    # {
    #     print "SLEEPING\n";
    #     sleep(5);
    #     redo;
    # }

来自perdoc -f redo

  

&#34;重做&#34;命令重新启动循环块而不再评估条件。 &#34;继续&#34;块,如果有的话,不执行。如果省略LABEL,则该命令引用最内层的封闭循环。

看到你没有把你的代码放在一个循环中,对redo的调用没有任何效果。

相关问题