\Horde_Lock_Sql

The Horde_Lock_Sql driver implements a storage backend for the Horde_Lock API.

The table structure for the locks is as follows:

CREATE TABLE horde_locks (
    lock_id                  VARCHAR(36) NOT NULL,
    lock_owner               VARCHAR(32) NOT NULL,
    lock_scope               VARCHAR(32) NOT NULL,
    lock_principal           VARCHAR(255) NOT NULL,
    lock_origin_timestamp    BIGINT NOT NULL,
    lock_update_timestamp    BIGINT NOT NULL,
    lock_expiry_timestamp    BIGINT NOT NULL,
    lock_type                TINYINT NOT NULL,

    PRIMARY KEY (lock_id)
);

Copyright 2008-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Summary

Methods
Properties
Constants
__construct()
getLockInfo()
getLocks()
resetLock()
setLock()
clearLock()
doGC()
No public properties found
TYPE_EXCLUSIVE
TYPE_SHARED
PERMANENT
No protected methods found
$_params
$_logger
N/A
No private methods found
$_db
N/A

Constants

TYPE_EXCLUSIVE

TYPE_EXCLUSIVE

TYPE_SHARED

TYPE_SHARED

PERMANENT

PERMANENT

Properties

$_params

$_params : array

Driver parameters.

Type

array

$_logger

$_logger : \Horde_Log_Logger

Logger.

Type

\Horde_Log_Logger

$_db

$_db : \Horde_Db_Adapter

Handle for the current database connection.

Type

\Horde_Db_Adapter

Methods

__construct()

__construct(array  $params = array()) 

Constructor.

Parameters

array $params

Parameters:

'db' - (Horde_Db_Adapter) [REQUIRED] The DB instance.
'table' - (string) The name of the lock table in 'database'.
          DEFAULT: 'horde_locks'

Throws

\Horde_Lock_Exception

getLockInfo()

getLockInfo(string  $lockid) : array

Return an array of information about the requested lock.

Parameters

string $lockid

Lock ID to look up.

Returns

array —

Lock information.

getLocks()

getLocks(string  $scope = null, string  $principal = null, integer  $type = null) : array

Return a list of valid locks with the option to limit the results by principal, scope and/or type.

Parameters

string $scope

The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together.

string $principal

Principal for which to check for locks

integer $type

Only return locks of the given type. Defaults to null, or all locks

Returns

array —

Array of locks with the ID as the key and the lock details as the value. If there are no current locks this will return an empty array.

resetLock()

resetLock(string  $lockid,   $lifetime) : boolean

Extend the valid lifetime of a valid lock to now + $lifetime.

Parameters

string $lockid

Lock ID to reset. Must be a valid, non-expired lock.

$lifetime

Returns

boolean —

Returns true on success.

setLock()

setLock(string  $requestor, string  $scope, string  $principal, integer  $lifetime = 1,   $type = \Horde_Lock::TYPE_SHARED) : mixed

Sets a lock on the requested principal and returns the generated lock ID.

Parameters

string $requestor

User ID of the lock requestor.

string $scope

The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together.

string $principal

A principal on which a lock should be granted. The format can be any string but is suggested to be in URI form.

integer $lifetime

Time (in seconds) for which the lock will be considered valid.

$type

Returns

mixed —

A string lock ID.

clearLock()

clearLock(string  $lockid) : boolean

Removes a lock given the lock ID.

NOTE: No security checks are done in the Horde_Lock API. It is expected that the calling application has done all necessary security checks before requesting a lock be cleared.

Parameters

string $lockid

The lock ID as generated by a previous call to setLock()

Returns

boolean —

Returns true on success.

doGC()

doGC() 

Do garbage collection needed for the driver.