Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
core\lock\file_lock_factory Class Reference

Flock based file locking factory. More...

Inheritance diagram for core\lock\file_lock_factory:
core\lock\lock_factory

Public Member Functions

 __construct ($type, ?string $lockdirectory=null)
 Create this lock factory.
 
 extend_lock (lock $lock, $maxlifetime=86400)
 Extend a lock that was previously obtained with @lock.
 
 get_lock ($resource, $timeout, $maxlifetime=86400)
 Get a lock within the specified timeout or return false.
 
 is_available ()
 Is available.
 
 release_lock (lock $lock)
 Release a lock that was previously obtained with @lock.
 
 supports_auto_release ()
 This lock type will be automatically released when a process ends.
 
 supports_recursion ()
 Multiple locks for the same resource cannot be held from a single process.
 
 supports_timeout ()
 Return information about the blocking behaviour of the lock type on this platform.
 

Protected Member Functions

 get_debug_info ()
 Get some info that might be useful for debugging.
 

Protected Attributes

string $lockdirectory
 $lockdirectory - Full system path to the directory used to store file locks.
 
string $type
 $type - The type of lock, e.g.
 
boolean $verbose
 $verbose - If true, debugging info about the owner of the lock will be written to the lock file.
 

Detailed Description

Flock based file locking factory.

The file lock factory returns file locks locked with the flock function. Works OK, except on some NFS, exotic shared storage and exotic server OSes (like windows). On windows, a second attempt to get a lock will block indefinitely instead of timing out.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core\lock\file_lock_factory::__construct ( $type,
?string $lockdirectory = null )

Create this lock factory.

Parameters
string$type- The type, e.g. cron, cache, session
string | null$lockdirectory- Optional path to the lock directory, to override defaults.

Member Function Documentation

◆ extend_lock()

core\lock\file_lock_factory::extend_lock ( lock $lock,
$maxlifetime = 86400 )

Extend a lock that was previously obtained with @lock.

Deprecated
since Moodle 3.10.
Parameters
lock$lock- not used
int$maxlifetime- not used
Return values
boolean- true if the lock was extended.

Implements core\lock\lock_factory.

◆ get_debug_info()

core\lock\file_lock_factory::get_debug_info ( )
protected

Get some info that might be useful for debugging.

Return values
boolean- string

◆ get_lock()

core\lock\file_lock_factory::get_lock ( $resource,
$timeout,
$maxlifetime = 86400 )

Get a lock within the specified timeout or return false.

Parameters
string$resource- The identifier for the lock. Should use frankenstyle prefix.
int$timeout- The number of seconds to wait for a lock before giving up.
int$maxlifetime- Unused by this lock type.
Return values
boolean- true if a lock was obtained.

Implements core\lock\lock_factory.

◆ is_available()

core\lock\file_lock_factory::is_available ( )

Is available.

Return values
boolean- True if preventfilelocking is not set - or the file_lock_root is not in dataroot.

Implements core\lock\lock_factory.

◆ release_lock()

core\lock\file_lock_factory::release_lock ( lock $lock)

Release a lock that was previously obtained with @lock.

Parameters
lock$lock- A lock obtained from this factory.
Return values
boolean- true if the lock is no longer held (including if it was never held).

Implements core\lock\lock_factory.

◆ supports_auto_release()

core\lock\file_lock_factory::supports_auto_release ( )

This lock type will be automatically released when a process ends.

Return values
boolean- True

Implements core\lock\lock_factory.

◆ supports_recursion()

core\lock\file_lock_factory::supports_recursion ( )

Multiple locks for the same resource cannot be held from a single process.

Deprecated
since Moodle 3.10.
Return values
boolean- False

Implements core\lock\lock_factory.

◆ supports_timeout()

core\lock\file_lock_factory::supports_timeout ( )

Return information about the blocking behaviour of the lock type on this platform.

Return values
boolean- False if attempting to get a lock will block indefinitely.

Implements core\lock\lock_factory.

Member Data Documentation

◆ $type

string core\lock\file_lock_factory::$type
protected

$type - The type of lock, e.g.

cache, cron, session.


The documentation for this class was generated from the following file: