VERSION$Id: Lockfile.pm,v 0.65 2011/12/08 07:53:07 acorliss Exp $
$rv = plock($lockfile);
$rv = punlock($lockfile);
$rv = pcloseLockfile($lockfile);
DESCRIPTIONThis modules provides a relatively safe locking mechanism across multiple processes. This does not work over NFS or across remote systems, this is only intended for use on a single system at a time, and only on those that support flock.
sysopen is used to avoid race conditions with multiple process attempting to create the same file simultaneously.
$rv = plock($filename);
This function attempts to safely create or open the lockfile. It uses sysopen with O_CREAT | O_EXCL to avoid race conditions with other processes. Returns a true if successful.
Your can pass an optional second argument which would be a string of either 'write' or 'shared'. The default is 'write', which locks the file in exclusive write mode.
You can pass an optional third argument which would be the lockfile filesystem permissions if the file is created. The default is 0600.
NOTE: This function will block until the advisory lock is granted.
$rv = punlock($filename);
This function removes any existing locks on the specified filename using flock. If no previous lock existed or it was successful it returns true. This does not, however, close the open filehandle to the lockfile.
$rv = pcloseLockfile($filename);
This function releases any existing locks and closes the open filehandle to the lockfile. Returns true if the file isn't currently open or the operation succeeds.