Call cleanup code in mod_perl environment

Some quotes to choose from practical mod_perl

"Typically, a single process serves many requests before it leaves, so END blocks cannot be used if they are expected to do something at the end of each request processing."

So in my a.cgi script:

my $flag = 1;

END {
    # Value for $flag is undefined, if this script is run under mod_perl. 
    # END block code only executed when process to handle a.cgi exit. 
    # I wish to execute some code, just before process to handle a.cgi exit.
    if ($flag) {
        # clean up code.
    }
}

The book resumes $ r-> register_cleanup (sub {#cleanup});

but

  • How can I get $ r in a.cgi script?
  • Can a routine access a variable of my area flag?
  • This parameter $ r-> register_cleanup should be placed in a.cgi script? I only need the cleanup code for a.cgi script. Not everything else.
+3
source share
2 answers
+4

, script, mod_perl, CGI, , Apache:: Registry, .

, , CGI script.

, mod_perl. . - :

unless ($ENV{MOD_PERL})
{
   #... cleanup code here.
}

, - , script Apache:: Registry.

, CGI:

unless ($ENV{MOD_PERL})
{
   cleanup_sub();
}

:

my $r = Apache->request;
$r->register_cleanup(sub { cleanup_sub() } );
+1

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


All Articles