Download the PHP package mpyw/laravel-database-advisory-lock without Composer

On this page you can find all versions of the php package mpyw/laravel-database-advisory-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?
mpyw/laravel-database-advisory-lock
Rate from 1 - 5
Rated 5.00 based on 2 reviews

Informations about the package laravel-database-advisory-lock

Laravel Database Advisory Lock Build Status Coverage Status

Advisory Locking Features of Postgres/MySQL/MariaDB on Laravel

Requirements

Package Version Mandatory
PHP ^8.0.2
Laravel ^9.0 || ^10.0
PHPStan >=1.1
RDBMS Version
Postgres >=9.1.14
MySQL >=5.7.5
MariaDB >=10.0.15

Installing

Basic usage

[!IMPORTANT] The default implementation is provided by ConnectionServiceProvider, however, package discovery is not available. Be careful that you MUST register it in config/app.php by yourself.

Advanced Usage

[!TIP] You can extend Connection classes with AdvisoryLocks trait by yourself.

Implementation Details

Key Hashing Algorithm

Locking Methods

Postgres MySQL/MariaDB
Session-Level Locking
Transaction-Level Locking

Timeout Values

Postgres MySQL MariaDB
Timeout: 0 (default; immediate, no wait)
Timeout: positive-int
Timeout: negative-int (infinite wait)
Timeout: float

Caveats about Transaction Levels

Key Principle

Always avoid nested transactions when using advisory locks to ensure adherence to the S2PL (Strict 2-Phase Locking) principle.

Recommended Approach

When transactions and advisory locks are related, either locking approach can be applied.

[!NOTE] Transaction-Level Locks:
Acquire the lock at the transaction nesting level 1, then rely on automatic release mechanisms.

[!NOTE] Session-Level Locks:
Acquire the lock at the transaction nesting level 0, then proceed to call DB::transaction() call.

[!WARNING] When writing logic like this, DatabaseTruncation must be used instead of RefreshDatabase.

Considerations

[!CAUTION] Transaction-Level Locks:
Don't take transaction-level locks in nested transactions. They are unaware of Laravel's nested transaction emulation.

[!CAUTION] Session-Level Locks:
Don't take session-level locks in the transactions when the content to be committed by the transaction is related to the advisory locks.

What would happen if we released a session-level lock within a transaction? Let's verify this with a timeline chart, assuming a READ COMMITTED isolation level on Postgres. The bank account X is operated from two sessions A and B concurrently.

Session A Session B
BEGIN
BEGIN
pg_advisory_lock(X)
pg_advisory_lock(X)
Fetch balance of User X
(Balance: 1000 USD)
Deduct 800 USD if balance permits
(Balance: 1000 USD → 200 USD)
pg_advisory_unlock(X)
Fetch balance of User X
(Balance: 1000 USD :heavy_exclamation_mark:)
Deduct 800 USD if balance permits
(Balance: 1000 USD → 200 USD :bangbang:)
COMMIT
pg_advisory_unlock(X)
Fetch balance of User X
(Balance: 200 USD)
COMMIT
Fetch balance of User X
(Balance: -600 USD :interrobang::interrobang::interrobang:)

All versions of laravel-database-advisory-lock with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0.2
ext-pdo Version *
illuminate/events Version ^9.0 || ^10.0 || ^11.0
illuminate/support Version ^9.0 || ^10.0 || ^11.0
illuminate/database Version ^9.0 || ^10.0 || ^11.0
illuminate/contracts Version ^9.0 || ^10.0 || ^11.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 mpyw/laravel-database-advisory-lock contains the following files

Loading the files please wait ....