TYPO3
7.6
|
Public Member Functions | |
__construct ($id, $method=self::LOCKING_METHOD_SIMPLE, $loops=0, $step=0) | |
__destruct () | |
acquire () | |
acquireExclusiveLock () | |
acquireSharedLock () | |
release () | |
getMethod () | |
getId () | |
getResource () | |
getLockStatus () | |
isLocked () | |
setSyslogFacility ($syslogFacility) | |
setEnableLogging ($isLoggingEnabled) | |
sysLog ($message, $severity=0) | |
Public Attributes | |
const | LOCKING_METHOD_SIMPLE = 'simple' |
const | LOCKING_METHOD_FLOCK = 'flock' |
const | LOCKING_METHOD_SEMAPHORE = 'semaphore' |
const | LOCKING_METHOD_DISABLED = 'disable' |
const | FILE_LOCK_FOLDER = 'typo3temp/locks/' |
Protected Member Functions | |
getSemaphore () | |
createPathIfNeeded () | |
Protected Attributes | |
$method = '' | |
$id | |
$resource | |
$filePointer | |
$isAcquired = false | |
$loops = 150 | |
$step = 200 | |
$syslogFacility = 'cms' | |
$isLoggingEnabled = true | |
TYPO3 locking class This class provides an abstract layer to various locking features for TYPO3
It is intended to blocks requests until some data has been generated. This is especially useful if two clients are requesting the same website short after each other. While the request of client 1 triggers building and caching of the website, client 2 will be waiting at this lock.
Definition at line 26 of file Locker.php.
__construct | ( | $id, | |
$method = self::LOCKING_METHOD_SIMPLE , |
|||
$loops = 0 , |
|||
$step = 0 |
|||
) |
Constructor: initializes locking, check input parameters and set variables accordingly.
Parameters $loops and $step only apply to the locking method LOCKING_METHOD_SIMPLE.
string | $id | ID to identify this lock in the system |
string | $method | Define which locking method to use. Use one of the LOCKING_METHOD_* constants. Defaults to LOCKING_METHOD_SIMPLE. Use '' to use setting from Install Tool. |
int | $loops | Number of times a locked resource is tried to be acquired. |
int | $step | Milliseconds after lock acquire is retried. $loops * $step results in the maximum delay of a lock. |
\RuntimeException | |
\InvalidArgumentException |
Definition at line 94 of file Locker.php.
References $GLOBALS, Locker\$id, Locker\$loops, Locker\$method, Locker\$step, Locker\createPathIfNeeded(), and GeneralUtility\logDeprecatedFunction().
__destruct | ( | ) |
Destructor: Releases lock automatically when instance is destroyed and release resources
Definition at line 131 of file Locker.php.
References GeneralUtility\isAllowedAbsPath(), GeneralUtility\isFirstPartOfStr(), and Locker\release().
acquire | ( | ) |
Acquire a lock and return when successful.
It is important to know that the lock will be acquired in any case, even if the request was blocked first. Therefore, the lock needs to be released in every situation.
\RuntimeException |
Definition at line 175 of file Locker.php.
References Locker\$filePointer, Locker\$isAcquired, Locker\$loops, elseif, GeneralUtility\fixPermissions(), Locker\getSemaphore(), Locker\sysLog(), and GeneralUtility\SYSLOG_SEVERITY_WARNING.
acquireExclusiveLock | ( | ) |
Try to acquire an exclusive lock
\RuntimeException |
Definition at line 253 of file Locker.php.
References Locker\$filePointer, Locker\$isAcquired, Locker\$loops, GeneralUtility\fixPermissions(), Locker\getSemaphore(), Locker\sysLog(), and GeneralUtility\SYSLOG_SEVERITY_WARNING.
acquireSharedLock | ( | ) |
Try to acquire a shared lock
(Only works for the flock() locking method currently)
\RuntimeException |
Definition at line 313 of file Locker.php.
References Locker\$isAcquired.
|
protected |
Tests if the directory for simple locks is available. If not, the directory will be created. The lock path is usually below typo3temp, typo3temp itself should exist already
\RuntimeException | If path couldn't be created. |
Definition at line 493 of file Locker.php.
References Locker\$id, and GeneralUtility\mkdir().
Referenced by Locker\__construct().
getId | ( | ) |
Return the ID which is currently used
Definition at line 389 of file Locker.php.
References Locker\$id.
getLockStatus | ( | ) |
Return the local status of a lock
Definition at line 410 of file Locker.php.
References Locker\$isAcquired.
Referenced by TypoScriptFrontendController\releasePageGenerationLock().
getMethod | ( | ) |
Return the locking method which is currently used
Definition at line 379 of file Locker.php.
References Locker\$method.
getResource | ( | ) |
Return the resource which is currently used. Depending on the locking method this can be a filename or a semaphore resource.
Definition at line 400 of file Locker.php.
References Locker\$resource.
|
protected |
Tries to allocate the semaphore
\RuntimeException |
Definition at line 157 of file Locker.php.
Referenced by Locker\acquire(), and Locker\acquireExclusiveLock().
isLocked | ( | ) |
Return the global status of the lock
Definition at line 420 of file Locker.php.
References Locker\sysLog(), and GeneralUtility\SYSLOG_SEVERITY_WARNING.
release | ( | ) |
Release the lock
Definition at line 335 of file Locker.php.
References GeneralUtility\isAllowedAbsPath(), and GeneralUtility\isFirstPartOfStr().
Referenced by Locker\__destruct().
setEnableLogging | ( | $isLoggingEnabled | ) |
Enable/ disable logging
bool | $isLoggingEnabled |
Definition at line 465 of file Locker.php.
References Locker\$isLoggingEnabled.
setSyslogFacility | ( | $syslogFacility | ) |
Sets the facility (extension name) for the syslog entry.
string | $syslogFacility |
Definition at line 455 of file Locker.php.
References Locker\$syslogFacility.
sysLog | ( | $message, | |
$severity = 0 |
|||
) |
Adds a common log entry for this locking API using ::sysLog(). Example: 25-02-08 17:58 - cms: Locking [simple::0aeafd2a67a6bb8b9543fb9ea25ecbe2]: Acquired
string | $message | The message to be logged |
int | $severity | Severity - 0 is info (default), 1 is notice, 2 is warning, 3 is error, 4 is fatal error |
Definition at line 478 of file Locker.php.
Referenced by Locker\acquire(), Locker\acquireExclusiveLock(), and Locker\isLocked().
|
protected |
Definition at line 53 of file Locker.php.
Referenced by Locker\acquire(), and Locker\acquireExclusiveLock().
|
protected |
Definition at line 43 of file Locker.php.
Referenced by Locker\__construct(), Locker\createPathIfNeeded(), and Locker\getId().
|
protected |
Definition at line 58 of file Locker.php.
Referenced by Locker\acquire(), Locker\acquireExclusiveLock(), Locker\acquireSharedLock(), and Locker\getLockStatus().
|
protected |
Definition at line 78 of file Locker.php.
Referenced by Locker\setEnableLogging().
|
protected |
Definition at line 63 of file Locker.php.
Referenced by Locker\__construct(), Locker\acquire(), and Locker\acquireExclusiveLock().
|
protected |
Definition at line 38 of file Locker.php.
Referenced by Locker\__construct(), and Locker\getMethod().
|
protected |
Definition at line 48 of file Locker.php.
Referenced by Locker\getResource().
|
protected |
Definition at line 68 of file Locker.php.
Referenced by Locker\__construct().
|
protected |
Definition at line 73 of file Locker.php.
Referenced by Locker\setSyslogFacility().
const FILE_LOCK_FOLDER = 'typo3temp/locks/' |
Definition at line 33 of file Locker.php.
const LOCKING_METHOD_DISABLED = 'disable' |
Definition at line 31 of file Locker.php.
const LOCKING_METHOD_FLOCK = 'flock' |
Definition at line 29 of file Locker.php.
const LOCKING_METHOD_SEMAPHORE = 'semaphore' |
Definition at line 30 of file Locker.php.
const LOCKING_METHOD_SIMPLE = 'simple' |
Definition at line 28 of file Locker.php.