You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tobias Zeising <tz...@arsnavigandi.de> on 2007/08/28 09:16:52 UTC

PerlRequire executed 4 times on apache startup

Hi all,

I have a weird problem: on startup apache executes 4 times a Perl Script
I included via

 PerlPostConfigRequire startup.pl

in the httpd.conf. The startup script contains following code:

 #!/usr/bin/perl

 my $file = 'c:\tmp\test.txt';
 open(INFO ,">>$file") || die "Error $!";
 print INFO "test\n";
 close INFO;
 print STDERR "test...\n";
 1;

After starting the apache server (with an empty test.txt) the error.log
contains as expectet one time "test..." and the test.txt contains
curiously four times "test". That means apache has executed the
startup.pl four times.

I have found http://modperlbook.org/html/ch04_07.html but that "apache
config test" would only explain the execution of two times.

Actually the startup.pl contains some code for preloading a huge amount
of modules, so this needs about 10 seconds instead of 2 or 3.

Hope anybody knows or can explain this behaviour.

Thanks and best regards
 Tobi

Re: PerlRequire executed 4 times on apache startup

Posted by Foo JH <jh...@extracktor.com>.
I've had this same experience on Win32 Apache 2 as well. It could be 
related to the MPM model that the Win32 implementation employs.

Tobias Zeising wrote:
> Hi all,
>
> I have a weird problem: on startup apache executes 4 times a Perl Script
> I included via
>
>  PerlPostConfigRequire startup.pl
>
> in the httpd.conf. The startup script contains following code:
>
>  #!/usr/bin/perl
>
>  my $file = 'c:\tmp\test.txt';
>  open(INFO ,">>$file") || die "Error $!";
>  print INFO "test\n";
>  close INFO;
>  print STDERR "test...\n";
>  1;
>
> After starting the apache server (with an empty test.txt) the error.log
> contains as expectet one time "test..." and the test.txt contains
> curiously four times "test". That means apache has executed the
> startup.pl four times.
>
> I have found http://modperlbook.org/html/ch04_07.html but that "apache
> config test" would only explain the execution of two times.
>
> Actually the startup.pl contains some code for preloading a huge amount
> of modules, so this needs about 10 seconds instead of 2 or 3.
>
> Hope anybody knows or can explain this behaviour.
>
> Thanks and best regards
>  Tobi
>   


Re: PerlRequire executed 4 times on apache startup

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Tobias Zeising wrote:
> Hi all,
> 
> I have a weird problem: on startup apache executes 4 times a Perl Script
> I included via
> 
>  PerlPostConfigRequire startup.pl

Yes, as Foo observed, this will happen 2x on Unix, 4x on Windows due to the MPM.

Notice that 1x and 2x (and 5x and 8x and 11x upon restarts) are all occurring
in the parent.  They aren't in the worker process at all, they were only pre-
tested to ensure your script compiles and runs.

The 3x and 4x times are in the child process that serves your request.  First
to pretest the config (yes, again!) and then the copy that will persist until
the worker process terminates.

Upon a graceful restart, that copy dies, the config is reprocessed in the parent
1x only again, and then 2x in the child.

We could (obviously) dump the extra success-test in the child.  But doing so
would break a huge assumption by coders like yourselves that rely on the pre
test followed by the actual run.

On Unix, you will see it run 1x for config test, followed by the 2x for the
worker children.  On a graceful restart, you'll see it happen a 3x time, etc.

Bill