CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.4 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.4
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
      • Engine
      • Exception
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Interface LockInterface

Interface for lock engines.

Lock engines provide distributed locking mechanisms to prevent race conditions when multiple processes access shared resources.

Namespace: Cake\Lock

Method Summary

  • acquire() public

    Acquire a lock for the given resource.

  • acquireBlocking() public

    Acquire a lock, waiting up to $timeout seconds if necessary.

  • forceRelease() public

    Force release a lock without ownership verification.

  • isLocked() public

    Check if a resource is currently locked.

  • refresh() public

    Refresh a lock's TTL to extend its duration.

  • release() public

    Release a lock.

Method Detail

acquire() ¶ public

acquire(string $resource, int $ttl = 300): Cake\Lock\AcquiredLock|null

Acquire a lock for the given resource.

Parameters
string $resource

The resource identifier to lock.

int $ttl optional

Time-to-live in seconds. The lock will automatically expire after this duration to prevent deadlocks.

Returns
Cake\Lock\AcquiredLock|null

Returns an AcquiredLock on success, null on failure.

acquireBlocking() ¶ public

acquireBlocking(string $resource, int $ttl = 300, int $timeout = 10, int $retryInterval = 100): Cake\Lock\AcquiredLock|null

Acquire a lock, waiting up to $timeout seconds if necessary.

This method will block until the lock is acquired or the timeout is reached.

Parameters
string $resource

The resource identifier to lock.

int $ttl optional

Time-to-live in seconds for the lock.

int $timeout optional

Maximum time in seconds to wait for the lock.

int $retryInterval optional

Milliseconds to wait between retry attempts.

Returns
Cake\Lock\AcquiredLock|null

Returns an AcquiredLock on success, null on timeout.

forceRelease() ¶ public

forceRelease(string $resource): bool

Force release a lock without ownership verification.

WARNING: This should only be used for administrative purposes as it bypasses owner verification and may cause race conditions.

Parameters
string $resource

The resource identifier to force release.

Returns
bool

True if the lock was released, false otherwise.

isLocked() ¶ public

isLocked(string $resource): bool

Check if a resource is currently locked.

Note: This is a point-in-time check and the lock status may change immediately after this method returns.

Parameters
string $resource

The resource identifier to check.

Returns
bool

True if the resource is locked, false otherwise.

refresh() ¶ public

refresh(Cake\Lock\AcquiredLock $lock, int|null $ttl = null): bool

Refresh a lock's TTL to extend its duration.

This is useful for long-running operations that need to hold a lock longer than initially anticipated.

Parameters
Cake\Lock\AcquiredLock $lock

The lock instance to refresh.

int|null $ttl optional

New TTL in seconds. If null, uses the original TTL.

Returns
bool

True if the lock was refreshed, false otherwise.

release() ¶ public

release(Cake\Lock\AcquiredLock $lock): bool

Release a lock.

Parameters
Cake\Lock\AcquiredLock $lock

The lock instance to release.

Returns
bool

True if the lock was released, false otherwise.

OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs