Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: How to use Storable in CGI scripts

by kingman (Scribe)
on Nov 29, 2002 at 19:52 UTC ( [id://216584]=note: print w/replies, xml ) Need Help??


in reply to Re: How to use Storable in CGI scripts
in thread How to use Storable in CGI scripts

I found an article on this at The Perl Journal. Here's my second version:
#!/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;
And here's the Sem.pm code:
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;
Is there anyway to test this? Should I use the apache benchmark tool to send a bunch of concurrent requests to the cgi?

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
      shotgunefx++

      Thanks for pointing out LWP::Parallel::UserAgent. I need that functionality in something I need to write today. I decided to do my daily voting here before heading off to the CPAN. Luckily I stumbled across this node and now I know what I'll be trying first.

      Cheers.

      -- vek --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://216584]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-29 11:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found