Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 39 and 400] [Versions 400 and 403]

Defines abstract factory class for generating locks.

Copyright: Damyon Wiese 2013
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 108 lines (4 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

lock_factory:: (8 methods):
  __construct()
  supports_timeout()
  supports_auto_release()
  supports_recursion()
  is_available()
  get_lock()
  release_lock()
  extend_lock()


Interface: lock_factory  - X-Ref

Defines abstract factory class for generating locks.

__construct($type)   X-Ref
Define the constructor signature required by the lock_config class.

param: string $type - The type this lock is used for (e.g. cron, cache)

supports_timeout()   X-Ref
Return information about the blocking behaviour of the locks on this platform.

return: boolean - False if attempting to get a lock will block indefinitely.

supports_auto_release()   X-Ref
Will this lock be automatically released when the process ends.
This should never be relied upon in code - but is useful in the case of
fatal errors. If a lock type does not support this auto release,
the max lock time parameter must be obeyed to eventually clean up a lock.

return: boolean - True if this lock type will be automatically released when the current process ends.

supports_recursion()   X-Ref
Supports recursion.

return: boolean - True if attempting to get 2 locks on the same resource will "stack"

is_available()   X-Ref
Is available.

return: boolean - True if this lock type is available in this environment.

get_lock($resource, $timeout, $maxlifetime = 86400)   X-Ref
Get a lock within the specified timeout or return false.

return: \core\lock\lock|boolean - An instance of \core\lock\lock if the lock was obtained, or false.
param: string $resource - The identifier for the lock. Should use frankenstyle prefix.
param: int $timeout - The number of seconds to wait for a lock before giving up.
param: int $maxlifetime - The number of seconds to wait before reclaiming a stale lock.

release_lock(lock $lock)   X-Ref
Release a lock that was previously obtained with @lock.

return: boolean - True if the lock is no longer held (including if it was never held).
param: lock $lock - The lock to release.

extend_lock(lock $lock, $maxlifetime = 86400)   X-Ref
Extend the timeout on a held lock.

return: boolean - True if the lock was extended.
param: lock $lock - lock obtained from this factory
param: int $maxlifetime - new max time to hold the lock