How to limit runtime for a Perl script in IIS?

This is a public hosting environment. I manage the server, but not necessarily the content. I have a client with a Perl script that gets out of control from time to time and drains 50% of the processor until the process is killed.

With ASP scripts, I can limit the amount of time that the script can execute, and IIS just shuts it down, say, after 90 seconds. This does not work for Perl scripts since it works like a cgi process (and actually runs an external process to execute the script).

Similarly, methods that look for excessive resource consumption in a workflow will most likely not notice this, since the resource that is consumed (processor) is milled by the child process, not WP itself.

Is there a way to force IIS to abort a Perl script (or another cgi-type process) that takes too long? How??

+3
source share
4 answers

On a UNIX-type system, I would use a signal handler to catch ALRM events, and then use the alarm function to start a timer before starting an action, which, as I expected, could be a timeout. If the action is completed, I would use the alarm (0) to turn off the alarm and exit normally, otherwise the signal handler must raise it to gracefully close everything.

I did not work with perl on Windows at the time, and although Windows is somewhat POSIXy, I cannot guarantee that this will work; you will need to check perl documentation to see if signals are supported on your platform or to what extent.

alarm() Perl Cookbook. , :

eval {
    # Create signal handler and make it local so it falls out of scope
    # outside the eval block
    local $SIG{ALRM} = sub {
        print "Print this if we time out, then die.\n";
        die "alarm\n";
    };

    # Set the alarm, take your chance running the routine, and turn off
    # the alarm if it completes.
    alarm(90);
    routine_that_might_take_a_while();
    alarm(0);
};
+1

- ASP script . script ASP, - script .

+1

...

, script, -, , Googlebot " " . script - , . -, " " " ", " " , . - " ". Googlebot script .

, robots.txt Disallow:/ . Googlebot script , robots.txt.

, Microsoft Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) , Perl. exe , , Googlebot .

( , robots.txt ), IIS, *.googlebot.com, , , Google .

, !

+1

Source: https://habr.com/ru/post/1696983/


All Articles