Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Perl infinite loops!

by kilinrax (Deacon)
on Dec 06, 2000 at 20:36 UTC ( #45236=note: print w/replies, xml ) Need Help??


in reply to Perl infinite loops!

Somewhere near the top of your cgi script you could put something like the following:
alarm(180); # stop script after 3 minutes
Which will kill the cgi script's process (with a SIGALRM) 3 minutes after execution of that line of code.

You could even go as far as printing a warning message if the script is killed this way:
$SIG{ALRM} = \&sighandler; sub sighandler() { print "WARNING: Script timed out or was killed\n"; exit (0); }

Replies are listed 'Best First'.
Re: Re: Perl infinite loops!
by marvell (Pilgrim) on Dec 06, 2000 at 21:02 UTC
    It would be worth logging that to a file, or at least terminating the html fully. You wouldn't want a "Document contains no data" situation and no message logged.

    In order to do that, you may have to keep track of where you are. There may be other things to do before you can terminate the html or the script.

    This is not as simple as it seems.

    --
    Brother Marvell

Re: Re: Perl infinite loops!
by silicon39 (Initiate) on Dec 06, 2000 at 22:17 UTC
    This worked great, but I can't get the handler to work. It gives me a "Spurious backslash ignored" on the "$SIG{ALRM} = \&sighandler;" line. I'm not an advanced Perl programmer, so I'm not quite sure where to go, but the alarm() call worked well. Thanks. Ian. BTW, we're still on Perl 4.xxxx (Aaarrrrgh! Don't say anything about this!) :-)
      Iirc, the syntax in Perl 4 is:
      $SIG{ALRM} = 'sighandler';
      Though i could easily be wrong about that :-/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://45236]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-05-28 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (99 votes). Check out past polls.

    Notices?