in reply to Re: How to use Storable in CGI scripts
in thread How to use Storable in CGI scripts
And here's the Sem.pm code:#!/usr/bin/perl use strict; use warnings; use Sem; use Storable qw/lock_store lock_retrieve/; use CGI; my $q = new CGI; my $sem = Sem->new('semaphore.txt'); my $x = lock_retrieve('k.dat') or die "Can't open k.dat: $!"; $x->{counter}++; lock_store($x, 'k.dat') or die "Can't save k.dat: $!"; $sem->unlock; print $q->header;
Is there anyway to test this? Should I use the apache benchmark tool to send a bunch of concurrent requests to the cgi?package Sem; sub new { my $class = shift(@_); use Carp (); my $filespec = shift(@_) || Carp::croak("What filespec?"); open my $fh, ">", $filespec or Carp::croak("Can't open semaphore f +ile $filespec: $!"); chmod 0666, $filespec; # assuming you want it a+rw use Fcntl 'LOCK_EX'; flock $fh, LOCK_EX; return bless {'fh' => $fh}, ref($class) || $class; } sub unlock { close(delete $_[0]{'fh'} or return 0); return 1; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: How to use Storable in CGI scripts
by shotgunefx (Parson) on Nov 29, 2002 at 20:06 UTC | |
by vek (Prior) on Nov 30, 2002 at 18:05 UTC |