Mark Clements wrote:
> Gunnar Hjalmarsson wrote:
>> If I run this script:
>>
>> $count++;
>> print "Content-type: text/plain\n\n";
>> print $count;
>>
>> 20 times under mod_perl, it outputs:
>>
>> 1 1 1 1 2 1 1 1 2 2 1 3 2 1 3 2 2 3 4 4
>>
>> while I would have expected it to output:
>>
>> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
>
> apache is traditionally multiprocessed - there is no guarantee that
> a second or subsequent request will be served by the same child.
> Try
>
> print "$$ $count\n";
Aha, thanks!
As an exercise, just to convince myself, I put together the following
code:
use SDBM_File;
use Fcntl;
print "Content-type: text/plain\n\n";
my $file = '/path/to/file';
my $total;
$count ++;
tie my %counts, 'SDBM_File', $file, O_RDWR|O_CREAT, 0644;
$counts{$$} = $count;
for (sort keys %counts) {
print "$_: $counts{$_}\n";
$total += $counts{$_};
}
untie %counts;
print "\nTotal: $total\n";
Now the result is as expected:
10569: 2
10570: 3
10571: 2
10572: 2
10573: 3
10574: 2
10575: 4
10576: 2
Total: 20
Previously I have only played with mod_perl using my IndigoPerl
installation on Windows 98, which (I suppose) runs as one single process.
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl