fred has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -wT #use strict; use Fcntl qw( :DEFAULT :flock ); use DB_File; use constant COUNT_FILE => "/home/httpd/data/count.dbm"; my %count; my $url = $ENV{DOCUMENT_URI}; local *DBM; print "Content-type: text/plain\n\n"; if (my $db = tie %count, "DB_File", COUNT_FILE, O_RDWR | O_CREAT) { my $fd = $db->fd; open DBM, "+<&=$fd" or die "Could not dup DBM for lock: $!"; flock DBM, LOCK_EX; undef $db; $count{$url} = 0 unless exists $count{$url}; my $num_hits = ++$count{$url}; untie %count; close DBM; print "$num_hits\n"; } else { print "[Error processing counter data]\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: simple web counter
by merlyn (Sage) on Sep 15, 2000 at 10:40 UTC | |
by runrig (Abbot) on Sep 16, 2000 at 00:02 UTC | |
|
Re: simple web counter
by extremely (Priest) on Sep 15, 2000 at 08:17 UTC | |
by Anonymous Monk on Mar 18, 2017 at 13:56 UTC | |
by poj (Abbot) on Mar 18, 2017 at 14:23 UTC |