Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 403]

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.

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

Defines 1 class

file_lock_factory:: (9 methods):
  __construct()
  supports_timeout()
  supports_auto_release()
  is_available()
  supports_recursion()
  get_debug_info()
  get_lock()
  release_lock()
  extend_lock()


Class: file_lock_factory  - X-Ref

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.

__construct($type, ?string $lockdirectory = null)   X-Ref
Create this lock factory.

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

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

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

supports_auto_release()   X-Ref
This lock type will be automatically released when a process ends.

return: boolean - True

is_available()   X-Ref
Is available.

return: boolean - True if preventfilelocking is not set - or the file_lock_root is not in dataroot.

supports_recursion()   X-Ref
Multiple locks for the same resource cannot be held from a single process.

return: boolean - False

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

return: boolean - string

get_lock($resource, $timeout, $maxlifetime = 86400)   X-Ref
Get a lock within the specified timeout or return 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 - Unused by this lock type.
return: boolean - true if a lock was obtained.

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

param: lock $lock - A lock obtained from this factory.
return: boolean - true if the lock is no longer held (including if it was never held).

extend_lock(lock $lock, $maxlifetime = 86400)   X-Ref
Extend a lock that was previously obtained with @lock.

param: lock $lock - not used
param: int $maxlifetime - not used
return: boolean - true if the lock was extended.