TYPO3  7.6
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Locker Class Reference

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
 

Detailed Description

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.

Constructor & Destructor Documentation

__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.

Parameters
string$idID to identify this lock in the system
string$methodDefine 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$loopsNumber of times a locked resource is tried to be acquired.
int$stepMilliseconds after lock acquire is retried. $loops * $step results in the maximum delay of a lock.
Exceptions
\RuntimeException
\InvalidArgumentException
Deprecated:
since TYPO3 CMS 7, will be removed with TYPO3 CMS 8

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().

Member Function Documentation

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.

Returns
bool Returns TRUE if lock could be acquired without waiting, FALSE otherwise.
Exceptions
\RuntimeException
Deprecated:
since 6.2 - will be removed two versions later; use new API instead

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

Exceptions
\RuntimeException
Returns
bool Returns TRUE if the lock was acquired successfully

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)

Returns
bool Returns TRUE if the lock was acquired successfully
Exceptions
\RuntimeException

Definition at line 313 of file Locker.php.

References Locker\$isAcquired.

createPathIfNeeded ( )
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

Returns
void
Exceptions
\RuntimeExceptionIf 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

Returns
string Locking ID

Definition at line 389 of file Locker.php.

References Locker\$id.

getLockStatus ( )

Return the local status of a lock

Returns
bool Returns TRUE if lock is acquired by this process, FALSE otherwise

Definition at line 410 of file Locker.php.

References Locker\$isAcquired.

Referenced by TypoScriptFrontendController\releasePageGenerationLock().

getMethod ( )

Return the locking method which is currently used

Returns
string Locking method

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.

Returns
mixed Locking resource (filename as string or semaphore as resource)

Definition at line 400 of file Locker.php.

References Locker\$resource.

getSemaphore ( )
protected

Tries to allocate the semaphore

Returns
void
Exceptions
\RuntimeException

Definition at line 157 of file Locker.php.

Referenced by Locker\acquire(), and Locker\acquireExclusiveLock().

isLocked ( )

Return the global status of the lock

Returns
bool Returns TRUE if the lock is locked by either this or another process, FALSE otherwise

Definition at line 420 of file Locker.php.

References Locker\sysLog(), and GeneralUtility\SYSLOG_SEVERITY_WARNING.

release ( )

Release the lock

Returns
bool Returns TRUE on success or FALSE on failure

Definition at line 335 of file Locker.php.

References GeneralUtility\isAllowedAbsPath(), and GeneralUtility\isFirstPartOfStr().

Referenced by Locker\__destruct().

setEnableLogging (   $isLoggingEnabled)

Enable/ disable logging

Parameters
bool$isLoggingEnabled

Definition at line 465 of file Locker.php.

References Locker\$isLoggingEnabled.

setSyslogFacility (   $syslogFacility)

Sets the facility (extension name) for the syslog entry.

Parameters
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

Parameters
string$messageThe message to be logged
int$severitySeverity - 0 is info (default), 1 is notice, 2 is warning, 3 is error, 4 is fatal error
Returns
void

Definition at line 478 of file Locker.php.

Referenced by Locker\acquire(), Locker\acquireExclusiveLock(), and Locker\isLocked().

Member Data Documentation

$filePointer
protected

Definition at line 53 of file Locker.php.

Referenced by Locker\acquire(), and Locker\acquireExclusiveLock().

$id
protected

Definition at line 43 of file Locker.php.

Referenced by Locker\__construct(), Locker\createPathIfNeeded(), and Locker\getId().

$isAcquired = false
protected
$isLoggingEnabled = true
protected

Definition at line 78 of file Locker.php.

Referenced by Locker\setEnableLogging().

$loops = 150
protected

Definition at line 63 of file Locker.php.

Referenced by Locker\__construct(), Locker\acquire(), and Locker\acquireExclusiveLock().

$method = ''
protected

Definition at line 38 of file Locker.php.

Referenced by Locker\__construct(), and Locker\getMethod().

$resource
protected

Definition at line 48 of file Locker.php.

Referenced by Locker\getResource().

$step = 200
protected

Definition at line 68 of file Locker.php.

Referenced by Locker\__construct().

$syslogFacility = 'cms'
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.