It's quite simple really. You're running 2 instances of the script. To retain the value of $counter, read up the mod_perl documentation for tips.

CthuMP wrote:
I have follow simple script:
!#/usr/bin/perl

print "Content-Type: text/html\n\n";

print "Counter: " . (++$counter) . "\n";
print time(), "\n";

sleep(20);

print time(), "\n";

Starting that script twice in two different browser windows gives me same
results. In second window I start script after some period (about 10
seconds) after first script started. First and Second scripts ends at the
same time.
So, I misunderrstand, why results are same?
As I see it, apache must give work to second child processes for second
request (because first busy). And scripts must end works in different time
(first script in 10 seconds before second) and give different results (same
counter result, but different times).
Even if script runs sequentially for each request, results will difference
and second script ends after 30 seconds (10 remained for 1st script and 20
for 2nd). But it is not!
If I copy script and run two same scripts with different names it works
fine.


Second question about childs. I not fully understand, how childs work. One
child can handle only one script? It's important, because if one child can
handle different scripts, than module global variables saves their values
between different script calls.
For example, if script1 and script2 uses module My::TestPackage, first
script sets $My::TestPackage::variable = 123, then script2, after it
request, will see in $My::TestPackage::variable value 123, but I haven't
seen mention about that situation in official documentations.

Reply via email to