TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Locking\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()

TYPO3\CMS\Core\Locking\Locker::__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

Definition at line 94 of file Locker.php.

References $GLOBALS, TYPO3\CMS\Core\Locking\Locker\$id, TYPO3\CMS\Core\Locking\Locker\$loops, TYPO3\CMS\Core\Locking\Locker\$method, TYPO3\CMS\Core\Locking\Locker\$step, TYPO3\CMS\Core\Locking\Locker\createPathIfNeeded(), and TYPO3\CMS\Core\Utility\GeneralUtility\logDeprecatedFunction().

◆ __destruct()

TYPO3\CMS\Core\Locking\Locker::__destruct ( )

Destructor: Releases lock automatically when instance is destroyed and release resources

Definition at line 131 of file Locker.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\isAllowedAbsPath(), TYPO3\CMS\Core\Utility\GeneralUtility\isFirstPartOfStr(), and TYPO3\CMS\Core\Locking\Locker\release().

Member Function Documentation

◆ acquire()

TYPO3\CMS\Core\Locking\Locker::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

Definition at line 175 of file Locker.php.

References TYPO3\CMS\Core\Locking\Locker\$filePointer, TYPO3\CMS\Core\Locking\Locker\$isAcquired, TYPO3\CMS\Core\Locking\Locker\$loops, TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions(), TYPO3\CMS\Core\Locking\Locker\getSemaphore(), TYPO3\CMS\Core\Locking\Locker\sysLog(), and TYPO3\CMS\Core\Utility\GeneralUtility\SYSLOG_SEVERITY_WARNING.

◆ acquireExclusiveLock()

◆ acquireSharedLock()

TYPO3\CMS\Core\Locking\Locker::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

Definition at line 313 of file Locker.php.

References TYPO3\CMS\Core\Locking\Locker\$isAcquired.

◆ createPathIfNeeded()

TYPO3\CMS\Core\Locking\Locker::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

Definition at line 493 of file Locker.php.

References TYPO3\CMS\Core\Locking\Locker\$id, and TYPO3\CMS\Core\Utility\GeneralUtility\mkdir().

Referenced by TYPO3\CMS\Core\Locking\Locker\__construct().

◆ getId()

TYPO3\CMS\Core\Locking\Locker::getId ( )

Return the ID which is currently used

Returns
string Locking ID

Definition at line 389 of file Locker.php.

References TYPO3\CMS\Core\Locking\Locker\$id.

◆ getLockStatus()

TYPO3\CMS\Core\Locking\Locker::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 TYPO3\CMS\Core\Locking\Locker\$isAcquired.

Referenced by TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController\releasePageGenerationLock().

◆ getMethod()

TYPO3\CMS\Core\Locking\Locker::getMethod ( )

Return the locking method which is currently used

Returns
string Locking method

Definition at line 379 of file Locker.php.

References TYPO3\CMS\Core\Locking\Locker\$method.

◆ getResource()

TYPO3\CMS\Core\Locking\Locker::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 TYPO3\CMS\Core\Locking\Locker\$resource.

◆ getSemaphore()

TYPO3\CMS\Core\Locking\Locker::getSemaphore ( )
protected

Tries to allocate the semaphore

Returns
void
Exceptions

Definition at line 157 of file Locker.php.

Referenced by TYPO3\CMS\Core\Locking\Locker\acquire(), and TYPO3\CMS\Core\Locking\Locker\acquireExclusiveLock().

◆ isLocked()

TYPO3\CMS\Core\Locking\Locker::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 TYPO3\CMS\Core\Locking\Locker\sysLog(), and TYPO3\CMS\Core\Utility\GeneralUtility\SYSLOG_SEVERITY_WARNING.

◆ release()

TYPO3\CMS\Core\Locking\Locker::release ( )

Release the lock

Returns
bool Returns TRUE on success or FALSE on failure

Definition at line 335 of file Locker.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\isAllowedAbsPath(), and TYPO3\CMS\Core\Utility\GeneralUtility\isFirstPartOfStr().

Referenced by TYPO3\CMS\Core\Locking\Locker\__destruct().

◆ setEnableLogging()

TYPO3\CMS\Core\Locking\Locker::setEnableLogging (   $isLoggingEnabled)

Enable/ disable logging

Parameters
bool$isLoggingEnabled

Definition at line 465 of file Locker.php.

References TYPO3\CMS\Core\Locking\Locker\$isLoggingEnabled.

◆ setSyslogFacility()

TYPO3\CMS\Core\Locking\Locker::setSyslogFacility (   $syslogFacility)

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

Parameters
string$syslogFacility

Definition at line 455 of file Locker.php.

References TYPO3\CMS\Core\Locking\Locker\$syslogFacility.

◆ sysLog()

TYPO3\CMS\Core\Locking\Locker::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 TYPO3\CMS\Core\Locking\Locker\acquire(), TYPO3\CMS\Core\Locking\Locker\acquireExclusiveLock(), and TYPO3\CMS\Core\Locking\Locker\isLocked().

Member Data Documentation

◆ $filePointer

TYPO3\CMS\Core\Locking\Locker::$filePointer
protected

◆ $id

TYPO3\CMS\Core\Locking\Locker::$id
protected

◆ $isAcquired

◆ $isLoggingEnabled

TYPO3\CMS\Core\Locking\Locker::$isLoggingEnabled = true
protected

Definition at line 78 of file Locker.php.

Referenced by TYPO3\CMS\Core\Locking\Locker\setEnableLogging().

◆ $loops

TYPO3\CMS\Core\Locking\Locker::$loops = 150
protected

◆ $method

TYPO3\CMS\Core\Locking\Locker::$method = ''
protected

◆ $resource

TYPO3\CMS\Core\Locking\Locker::$resource
protected

Definition at line 48 of file Locker.php.

Referenced by TYPO3\CMS\Core\Locking\Locker\getResource().

◆ $step

TYPO3\CMS\Core\Locking\Locker::$step = 200
protected

Definition at line 68 of file Locker.php.

Referenced by TYPO3\CMS\Core\Locking\Locker\__construct().

◆ $syslogFacility

TYPO3\CMS\Core\Locking\Locker::$syslogFacility = 'cms'
protected

Definition at line 73 of file Locker.php.

Referenced by TYPO3\CMS\Core\Locking\Locker\setSyslogFacility().

◆ FILE_LOCK_FOLDER

◆ LOCKING_METHOD_DISABLED

◆ LOCKING_METHOD_FLOCK

const TYPO3\CMS\Core\Locking\Locker::LOCKING_METHOD_FLOCK = 'flock'

◆ LOCKING_METHOD_SEMAPHORE

const TYPO3\CMS\Core\Locking\Locker::LOCKING_METHOD_SEMAPHORE = 'semaphore'

◆ LOCKING_METHOD_SIMPLE