From gerry at osdc.com.au Mon Jul 25 04:55:14 2005 From: gerry at osdc.com.au (Gerry Quinlan) Date: Mon, 25 Jul 2005 21:55:14 +1000 Subject: [Canberra-pm] Open Source Developers Conference 2005 (Melbourne) Message-ID: <42E4D322.5070408@osdc.com.au> Hi I am a fellow Perl Monger and now assistant to the organising committee for the upcoming OSDC Conference 2005. Following the success of the Conference in 2004 we would again like to invite people to participate in the OSDC Conference 2005. Details of the Conference and Call for papers are on the osdc web site (see below). Regards Gerry Quinlan Member of OSDC 2005 Publicity Sub-Committee Announcement: OSDC 2005 is up and running. The second Australian OSDC (Open Source Developers' Conference) will be held on the 5th, 6th and 7th of December 2005 at Monash University in Melbourne. The 2004 Conference was an outstanding success with over 160 delegates attending, including a significant number from interstate and overseas. The quality of presentations and general enthusiasm of the attendees confirmed the growing reputation and strength of open source development in Australia. Most of last year's attendees plan to attend the conference again in 2005. In 2005, OSDC will be even bigger and better. OSDC is a great opportunity for open source devotees to attend an affordable conference where the main focus is software development. Companies and other organisations will find the conference an ideal avenue for providing professional development for staff, identifying trends and partners and promoting their services. The conference web site is: http://www.osdc.com.au From John.Hockaday at ga.gov.au Thu Jul 28 17:34:34 2005 From: John.Hockaday at ga.gov.au (John.Hockaday@ga.gov.au) Date: Fri, 29 Jul 2005 10:34:34 +1000 Subject: [Canberra-pm] How to flock a file for to ensure only one CGI BIN script process at a time Message-ID: <158ADDBA43E6C748BBD230A469EC6A4D0F009D@mail.ga.gov.au> Hi, I have a CGI-BIN script that chews up a lot of CPU and takes quite a while to run. I only want a select few users to run it one at a time. It isn't likely that users will want to run it very often. Once every three months is the expected frequency. I have put the script in an .httpaccess area that only these users can get to. The processSite sub routine is the bit that uses up CPU time. printBusy just tells the user to try again later because someone else is testing their site. I thought that flock would be the best method to use a lock file to stop any other users from running the script while someone else has it running. The trouble is that the script creates the lockFile and doesn't delete it. How can I get flock to check if the lockFile exists and if so send a busy message to CGI. Otherwise, set the lockFile, flock it and process the site? Any help would be greatly appreciated. Thanks. John This is part of the code that I tried: use CGI; use Fcntl qw(:DEFAULT :flock); my ($query) = new CGI; # If there is a zserver parameter then try to process the site. if ($query->param('zserver')) { $zserver = $query->param('zserver'); $port = $query->param('port'); $repository = $query->param('repository'); $title = $query->param('title'); $title = '"' . $title . '"'; # Check flock if flock send sorry being used wait # else set flock flock(LOCKFILE, LOCK_SH); sysopen(LOCKFILE, $lockFile, O_EXCL | O_CREAT) or &printBusy; &processSite(); # unlock flock close LOCKFILE; undef $lockFile; exit (0); # Else print the HTML input form. } else { &printInputPage; print "Loaded input page
\n" if $DEBUG; exit (0); } sub printBusy { my ($q) = new CGI; print $q->header; print html_util::process_html($head); print html_util::process_html($busy); print html_util::process_html($foot); undef $q; exit (0); } #End printBusy From pjf at perltraining.com.au Thu Jul 28 17:55:05 2005 From: pjf at perltraining.com.au (Paul Fenwick) Date: Fri, 29 Jul 2005 10:55:05 +1000 Subject: [Canberra-pm] How to flock a file for to ensure only one CGI BIN script process at a time In-Reply-To: <158ADDBA43E6C748BBD230A469EC6A4D0F009D@mail.ga.gov.au> References: <158ADDBA43E6C748BBD230A469EC6A4D0F009D@mail.ga.gov.au> Message-ID: <42E97E69.8040009@perltraining.com.au> G'day John, John.Hockaday at ga.gov.au wrote: [snip] > I thought that flock would be the best method to use a lock file to stop any > other users from running the script while someone else has it running. The > trouble is that the script creates the lockFile and doesn't delete it. How > can I get flock to check if the lockFile exists and if so send a busy message > to CGI. Otherwise, set the lockFile, flock it and process the site? If I understand you correctly, you only want a single copy of the CGI to be executing at once. The easy way to do this isn't to create a separate lockfile, but to instead lock your program itself. These are described in MJD's "Locking Tricks and Traps" that can be found at http://perl.plover.com/yak/flock/ . In a nutshell: use Fcntl qw(:flock); open(SELF, "< $0") or die "Cannot open $0 - $!\n"; flock(SELF, LOCK_EX | LOCK_NB) or die "Already running\n"; __END__ alternatively: flock(DATA, LOCK_EX | LOCK_NB) or die "Already Running\n"; # ... __DATA__ By opening and locking your own source file, you save all the hassle of trying to co-ordinate lockfile creation and deletion. All this assumes that you're running on a single machine, and not a farm of machines. Locking over a network filesystem has other hazards. Cheerio, Paul -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681