Class lockfile

Description

A class to handle a lockfile for a running process. The idea is you

create one of these for a process each time you run it. If the lockfile already exists, then

Located in /lockfile-defs.php (line 71)


	
			
Variable Summary
 mixed $errorcode
 mixed $exists
 mixed $freezesecs
 mixed $frozen
 mixed $killsecs
 mixed $lock_mins
 mixed $messages
 mixed $pid
Method Summary
 lockfile lockfile ([string $lockfilename = ""], [string $lockfiledir = "/tmp"], [integer $pid = ""])
 boolean create ()
 string errormsg ()
 boolean remove ()
 void set_timelimits (integer $killmins, integer $freezemins)
Variables
mixed $errorcode = 0 (line 87)

Latest error code

mixed $exists = false (line 89)

True if the lockfile exists

mixed $freezefilename = "" (line 75)

Name of freeze lockfile to create (internal)

mixed $freezesecs = 0 (line 81)

Lockfile age at which we should stop trying to kill hung process

mixed $frozen = false (line 91)

True if the freeze lockfile exists

mixed $killsecs = 0 (line 79)

Lockfile age at which we should assume process is hung

mixed $lockfilename = "" (line 73)

Name of the lockfile to create

mixed $lock_mins = 0 (line 83)

Minutes process has been locked for

mixed $messages = "" (line 85)

Latest error message

mixed $pid = "" (line 77)

Process ID of process lockfile is for

Methods
Constructor lockfile (line 99)

Make a new lockfile handler object.

lockfile lockfile ([string $lockfilename = ""], [string $lockfiledir = "/tmp"], [integer $pid = ""])
  • string $lockfilename: Name of the lockfile
  • string $lockfiledir: Directory to create lockfile in
  • integer $pid: Optional process ID (defaults to current pid)
create (line 171)

Create the lockfile. We only do this, obviously, if it doesn't already exist. If it DOES exist, then we make a lot of checks. If time-limits are set we possibly try to kill the process and remove the lockfile before creating our new one.

If we created a lockfile then we return true, and this measn the calling process should feel free to run. If we return false, then either the lock is valid, or an error condition is present, and the calling process should about/exit without running.

  • return: True if lockfile was created successfully, else false.
boolean create ()
errormsg (line 147)

Return any lockfile error message

  • return: Any error message associated with the lockfile
string errormsg ()
remove (line 264)

Remove the lockfile. Can't do this if the lock is frozen, which is deemed to require manual intervention.

  • return: True if the lock was removed successfully.
boolean remove ()
set_timelimits (line 125)

Set the time limits. Some commonsense has to be applied here. You

should pick times, in mins, which are sensible according to how frequently you are going to be checking the lockfiles. If, for example you pick killmins=5 and freezemins=10 and only run this every hour, then you will never give it chance to kill a hung process between the 5 and 10 mins mark. A better choice for that would be killmins=30 freezemins=130.

void set_timelimits (integer $killmins, integer $freezemins)
  • integer $killmins: Time after which process is assumed hung
  • integer $freezemins: Time after which we stop trying to kill it

Documentation generated by phpDocumentor 1.3.0RC3