Download the PHP package zaber-dev/laravel-lock without Composer

On this page you can find all versions of the php package zaber-dev/laravel-lock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-lock

Laravel Lock

Latest Version on Packagist Run Tests Total Downloads PHP Version Require License

Supports: Laravel 11, 12 & 13+ • PHP 8.2+ • Redis • Memcached • Database

Application-level distributed locking for Laravel. Prevent race conditions and concurrent execution across actions, workflows, and endpoints with automatic owner detection and cleanup.

Manage locks using cache or persistent database storage, attach them to Eloquent models, protect routes with middleware, and automatically track ownership — all through a clean, expressive API.

Unlike Laravel's low-level Cache::lock(), Laravel Lock elevates distributed locking into a first-class, entity-scoped application abstraction (Lock::for(...)) with owner detection and lifecycle events.


Quick Example


Common Use Cases

Laravel Lock is ideal for:


Why not Cache::lock()?

Laravel's Cache::lock() is an excellent low-level primitive for atomic locking.

Laravel Lock doesn't replace Cache::lock(). Instead, it builds on the same concept while providing higher-level application primitives for common Laravel workflows. Laravel Lock focuses on application-level locking with:


Why Laravel Lock?

While Cache::lock() handles basic mutex acquisition, Laravel Lock is engineered for entity-scoped, application-level mutual exclusion across your entire Laravel ecosystem.

Feature Cache::lock() Laravel Lock
Primary Purpose Low-level atomic mutex Application-level distributed locking
High-Level Fluent API (Lock::for()->ttl()) ❌ Manual ✅ Expressive & Clean (Lock::for())
Automatic Owner Resolution ❌ Manual Token ✅ Built-in (user_id, job, hash)
First-Class Eloquent Integration ($user->lock()) ❌ ✅ Native (HasLocks)
Persistent Database Storage ❌ Cache Only ✅ Both Cache & Database Supported
Success-Only / Auto-Release Route Middleware ❌ ✅ Built-in (RequireLock)
Polymorphic Target Scoping ❌ Manual Keys ✅ Automatic Key Mapping
Immutable DTOs (LockInfo) ❌ ✅ Strict (CarbonImmutable)
Automatic Database Pruning (model:prune) N/A ✅ Built-in (Prunable)
Custom Storage Extensibility (Lock::extend()) ❌ ✅ Closure / Container
Event Dispatching (LockAcquired / Released) ❌ ✅ Configurable Events

Features


Documentation


Installation

Ready to get started? Install the package with Composer:

Publish the configuration and database migrations:

Run migrations if you intend to use the database driver:


Configuration

The configuration file config/locks.php allows you to define your default storage engine, driver parameters, and event dispatching behaviors:


Usage Guide

1. The Fluent Lock API

The Lock facade provides an expressive builder interface for acquiring, checking, blocking, and releasing locks.

Acquiring & Checking a Lock

Atomic Block Execution (block)

For operations vulnerable to concurrent execution bursts, use the block() helper. block() automatically acquires the lock, executes your callback, and safely releases the lock inside a try...finally block:

Force Releasing Locks

If an administrative or recovery script needs to clear a locked resource regardless of owner:


2. Eloquent Model Integration (HasLocks)

Add the HasLocks trait to any Eloquent model to scope locks directly to that entity:

You can now interact directly with your model instance:

Polymorphic Database Querying

When using the database driver, HasLocks also exposes a locks() polymorphic relationship, allowing direct querying and bulk management:


3. Route Middleware

Protect routes declaratively without writing boilerplate checks in your controllers using the RequireLock middleware:

How the Middleware Works:


4. Working with Storage Backends (using & driver)

By default, the package uses the storage engine defined in config/locks.php. You can switch storage drivers on the fly per request or action:

Registering Custom Storage Drivers

You can extend the LockManager with your own storage drivers (e.g., DynamoDB, Redis Cluster) in your AppServiceProvider:


5. Database Pruning (Prunable)

When using the database driver, expired records are automatically marked for pruning via Laravel's Prunable trait on the ZaberDev\Lock\Models\LockModel model.

To clean up old records automatically, schedule Laravel's model:prune command in your console.php or Kernel.php:


6. Events

Whenever a lock is acquired, released, failed, or force-released, the package dispatches strongly typed events if enabled (locks.events.dispatch = true):

You can listen to these in your EventServiceProvider for logging, monitoring, or alerting.


Related Packages

This package is part of the ZaberDev Laravel Ecosystem (Laravel Productivity Toolkit) — a cohesive suite of high-level application primitives engineered for concurrency, state management, and resource allocation.

Explore the complete directory of packages, detailed use cases, and documentation in our Ecosystem Index Hub.


Testing & Quality

Run the comprehensive PHPUnit test suite locally:


Contributing

Thank you for considering contributing! Please ensure any pull requests include thorough PHPUnit tests covering unit, feature, and driver integration scenarios.


License

The MIT License (MIT). Please see LICENSE.md for more information.


Built with ❤️ as part of the ZaberDev Laravel Ecosystem.


All versions of laravel-lock with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
nesbot/carbon Version ^2.63|^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zaber-dev/laravel-lock contains the following files

Loading the files please wait ...