in reply to WWW::Curl pause conflict

From reading pause, you shouldn't be using pause, you should be using sleep

Replies are listed 'Best First'.
Re^2: WWW::Curl pause conflict
by krmx (Novice) on Sep 21, 2015 at 06:38 UTC
    Additional: I was wrong - using sleep instead of pause does not work. there is no difference whatsoever between:
    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; }
    and
    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 sleep; }
    The code gets stuck after 2 run samples. Always 2 . not sure why. It seems to me something between WWW::Culr (libcurl) and perl regarding alarms and timers.
        Thanks for pointers. It seems related the way libcurl handles signal handlers within. I have played around by setting: CURLOPT_NOSIGNAL used to disable the timeouts while the name resolve takes place.
        $http->setopt(CURLOPT_NOSIGNAL, 1); while (1) { my stuff here ... ### Interval pause; }
        http://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html This might not be smart if I really need to timeout, I think in for some reasons DNS calls are not functioning. I need to think.
Re^2: WWW::Curl pause conflict
by krmx (Novice) on Sep 21, 2015 at 05:06 UTC
    I understand that it is not safe to use sleep and a timer at the same time within Perl code. My sample uses POSIX timers and alarm. https://www.febo.com/pages/perl_alarm_code/ At the same time: this code works fine for other types of work, like here: https://github.com/kronometrix/recording/blob/master/bin/linux/cpurec