从实用的 mod_perl 中挑选一些引述
“通常,单个进程在退出之前会处理许多请求,因此如果希望在每个请求处理结束时执行某些操作,则不能使用 END 块。”
所以,在我的 a.cgi 脚本中:
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.
}
}
这本书重新开始 $r->register_cleanup(sub { #cleanup } );
然而,
- 如何在 a.cgi 脚本中获取 $r?
- 子例程可以访问我的范围标志变量吗?
- 这个 $r->register_cleanup 应该放在 a.cgi 脚本中吗?我只希望为 a.cgi 脚本执行清理代码。不是其余的。