Hi All,

I'm developing a new module for mod_perl 1.27, and I'm noticing that some code is getting executed twice when the Apache server starts up.

Here's a simple example. Say I have two modules in separate files:

package DoubleTest;
use strict;
my $seen;
sub test_seen {
$seen++;
warn "Seen: $seen\n"
}
1;

package TestSeen;
use strict;
use DoubleTest;
DoubleTest::test_seen();
1;

Then I have an httpd.conf with these two lines:

PerlModule DoubleTest
PerlModule TestSeen

When I start up Apache, I see "Seen: 1" print to the terminal, and then I see "Seen: 2" in the error log. For some reason, TestSeen is getting executed twice!

I did a quick search on perl.apache.org, and found this item:

http://perl.apache.org/docs/1.0/guide/ config.html#Apache_Restarts_Twice_On_Start

However, this seems to indicate that, first, modules will be executed twice on restart but not on start, and second, that it doesn't affect PerlModule directives. What I'm seeing above doesn't seem to bear this out.

Thanks to that item in the guide, I did figure out how to circumvent the problem by checking $Apache::Server::Starting in DoubleTest::test_seen():

sub test_seen {
return if $Apache::Server::Starting;
$seen++;
warn "Seen: $seen\n"
}

So I'm fine with this workaround, but not sure why it's necessary. I could also change TestSeen.pm to only call test_seen() in a BEGIN block or something (since the modules seems to be compiled only once, but run twice), but since the module I'm actually writing is the equivalent of DoubleTest with TestSeen as the client, I'd rather not impose that on the users of my module.

Explanations and other suggested approaches to handling this problem will be most welcome.

TIA,

David

--
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: [EMAIL PROTECTED]

Reply via email to