in reply to time in mod_perl
I bet you're using an Apache::Registry script with a global my variable.
my $t = time; sub print_t { print("$t\n"); } print_t(); print("$t\n");
This is not a mod_perl problem, but an Apache::Registry problem. Apache::Registry puts your script in a function it executes every time the page is requested.
my $script = sub { my $t = time; sub print_t { print("$t\n"); } print_t(); print("$t\n"); }; $script->(); # A page request sleep(2); $script->(); # A page request
the problem is that print_t closed over $t, so it always refers to $t original value, even though $t changes.
1175021938 1175021938 1175021938 <- print_t still references the original $t 1175021940
The fix is to use package variables instead of lexical variables for globals in Apache::Registry scripts.
my $script = sub { our $t = time; sub print_t { print("$t\n"); } print_t(); print("$t\n"); }; $script->(); # A page request sleep(2); $script->(); # A page request
1175022050 1175022050 1175022052 1175022052
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: time in mod_perl
by Bruce32903 (Scribe) on Mar 27, 2007 at 20:08 UTC | |
by jettero (Monsignor) on Mar 28, 2007 at 13:14 UTC | |
|
Re^2: time in mod_perl
by Bruce32903 (Scribe) on Mar 27, 2007 at 20:18 UTC | |
by Fletch (Bishop) on Mar 27, 2007 at 21:25 UTC |