krmx has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use WWW::Curl::Easy; use POSIX qw(pause); use Time::HiRes qw(time alarm setitimer sleep ITIMER_REAL); use Getopt::Std; ### Process command line args usage() if defined $ARGV[0] and $ARGV[0] eq "--help"; getopts('hvV') or usage(); # process [interval [count]], my ( $interval, $loop_max ); if ( defined $ARGV[0] ) { $interval = $ARGV[0]; $loop_max = defined $ARGV[1] ? $ARGV[1] : 2**32; usage() if $interval == 0; } else { $interval = 1; $loop_max = 1; } ### Variables my $loop = 0; # current loop number # how often do we trigger (seconds)? my $first_interval = $interval; # signal handler is empty $SIG{ALRM} = sub { }; # first value is the initial wait, second is the wait thereafter setitimer( ITIMER_REAL, $first_interval, $interval ); my $http = WWW::Curl::Easy->new(); if (&WWW::Curl::Easy::version() !~ /ssl|nss/i) { die "No SSL support"; } # Get the results while (1) { my $url = "http://kronometrix.org/"; $http->setopt(CURLOPT_URL, $url); my $retcode = $http->perform(); ## Get the results my $response = $http->getinfo(CURLINFO_HTTP_CODE); if ($retcode == 0) { print "Ok, Status: $response\n"; } else { print "Error, Status: $response\n"; } ### Check for end last if ++$loop == $loop_max; ### Interval pause; # sleep $interval; }
and if I replace pause with sleep this works fine. Im using this alarms with timers to trigger certain actions at specific time intervals.
Anyone any ideas why WWW::Curl breaks down on pause or am I using this wrong ?. Many thanks for help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WWW::Curl pause conflict
by Anonymous Monk on Sep 20, 2015 at 23:47 UTC | |
by krmx (Novice) on Sep 21, 2015 at 06:38 UTC | |
by Anonymous Monk on Sep 21, 2015 at 07:00 UTC | |
by krmx (Novice) on Sep 21, 2015 at 07:17 UTC | |
by krmx (Novice) on Sep 21, 2015 at 05:06 UTC | |
by Anonymous Monk on Sep 21, 2015 at 06:52 UTC | |
|
Re: WWW::Curl pause conflict
by Anonymous Monk on Sep 21, 2015 at 18:46 UTC |