mohamedhekal / lockguard
Safe distributed locking helpers for Laravel with owner tokens and job middleware
v0.1.0
2026-07-16 14:23 UTC
Requires
- php: ^8.2
- illuminate/cache: ^11.0|^12.0
- illuminate/contracts: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.18
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/phpstan: ^2.0
README
Search terms: laravel, redis, distributed-locks, concurrency, mutex, php, laravel-package, locking, cache-lock, jobs.
Safe distributed locking helpers for Laravel: with(), owner-aware cache locks, HTTP middleware, and queue WithoutOverlapping.
Installation
composer require mohamedhekal/lockguard php artisan vendor:publish --tag=lockguard-config
Quick start
use Hekal\LockGuard\Facades\LockGuard; LockGuard::with('inventory:sku-1', function () { // exclusive critical section });
HTTP:
Route::middleware('lockguard:checkout:session,15')->post('/checkout', ...);
Queue:
public function middleware(): array { return [new \Hekal\LockGuard\Support\WithoutOverlapping('sync:tenant-1')]; }
Notes
- Uses Laravel cache locks. Prefer Redis in production.
default_wait_seconds=0means fail fast (throw) when the lock is busy.- This is not Redlock multi-node consensus; it is a practical Laravel lock layer.
Testing
composer install && composer test
License
MIT