Download the PHP package mvonline/locker without Composer
On this page you can find all versions of the php package mvonline/locker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mvonline/locker
More information about mvonline/locker
Files in mvonline/locker
Package locker
Short Description A comprehensive, cache-driver-agnostic distributed locking framework for Laravel
License MIT
Informations about the package locker
Locker - Distributed Locking Framework for Laravel
A comprehensive, cache-driver-agnostic distributed locking framework for Laravel that extends Laravel's cache abstraction while remaining compatible with all native cache drivers.
Features
- 12 Lock Types: Simple, Safe, Redlock, Reentrant, Read-Write, Semaphore, Fair, Fencing Token, Striped, Multi-Resource, Watchdog, and Leased locks
- Cache Driver Agnostic: Works with Redis, Database, File, Memcached, and Array cache drivers
- Fluent API: Chainable, intuitive interface
- Event System: Comprehensive event dispatching for lock lifecycle
- Automatic Release: Locks are automatically released after callback execution
- Blocking & Non-blocking: Configurable retry logic with exponential backoff
- Fully Tested: Comprehensive test suite targeting 100% coverage
Installation
Configuration
Publish the configuration file:
Quick Start
Basic Usage
Quick Helpers
Using the HasLocks Trait
Lock Types
1. Simple Lock
Basic atomic lock with no ownership validation.
2. Safe Lock
Lock with unique owner token to prevent accidental unlock.
3. Redlock (Redis-only)
Distributed lock using Redis Redlock algorithm with quorum.
4. Reentrant Lock
Same owner can re-acquire the lock multiple times.
5. Read-Write Lock
Multiple readers or exclusive writer.
6. Semaphore Lock
Allows N concurrent holders.
7. Fair Lock
FIFO ordering prevents starvation.
8. Fencing Token Lock
Monotonic token per acquisition prevents split-brain writes.
9. Striped Lock
Hash-based sharding reduces contention.
10. Multi-Resource Lock
Atomic multi-lock acquisition with deadlock prevention.
11. Watchdog Lock
Auto-renewal of TTL before expiration.
12. Leased Lock
Hard TTL expiration with explicit renewal required.
Manual Lock Control
Blocking with Retry
Events
The package dispatches events for lock lifecycle:
LockAcquired: When a lock is successfully acquiredLockReleased: When a lock is releasedLockFailed: When lock acquisition failsLockTimeout: When lock acquisition times outLockExtended: When a lock's TTL is extended
Listen to events:
Status & Admin
Exceptions
The package throws custom exceptions:
LockAcquisitionException: When lock acquisition failsLockReleaseException: When lock release failsLockTimeoutException: When lock acquisition times outUnsupportedDriverException: When lock type is not supported by driverLockOwnershipException: When lock ownership validation fails
Cache Drivers
The package works with all Laravel cache drivers:
- Redis: Full support for all lock types including Redlock
- Database: Full support for all lock types
- File: Full support for all lock types
- Memcached: Full support for all lock types
- Array: Full support (for testing only)
Testing
Requirements
- PHP 8.1+
- Laravel 10+, 11+, or 12+
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
All versions of locker with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/cache Version ^10.0|^11.0|^12.0
illuminate/events Version ^10.0|^11.0|^12.0
illuminate/contracts Version ^10.0|^11.0|^12.0