cybercog / php-db-locker
PHP application-level database locking mechanisms
Fund package maintenance!
paypal.me/antonkomarev
Requires
- php: ^8.1
- ext-pdo: *
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-11-19 16:26:16 UTC
README
Introduction
PHP application-level database locking mechanisms to implement concurrency control patterns.
Supported drivers:
- Postgres
Installation
Pull in the package through Composer.
composer require cybercog/php-db-locker
Usage
Postgres
Transaction-level advisory lock
$dbConnection = new PDO($dsn, $username, $password); $postgresLocker = new PostgresAdvisoryLocker(); $postgresLockId = PostgresLockId::fromLockId(new LockId('user', '4')); $dbConnection->beginTransaction(); $isLockAcquired = $postgresLocker->acquireLockWithinTransaction($dbConnection, $postgresLockId); if ($isLockAcquired) { // Execute logic if lock was successful } else { // Execute logic if lock acquisition has been failed } $dbConnection->commit();
Session-level advisory lock
$dbConnection = new PDO($dsn, $username, $password); $postgresLocker = new PostgresAdvisoryLocker(); $postgresLockId = PostgresLockId::fromLockId(new LockId('user', '4')); $isLockAcquired = $postgresLocker->acquireLock($dbConnection, $postgresLockId); if ($isLockAcquired) { // Execute logic if lock was successful } else { // Execute logic if lock acquisition has been failed } $postgresLocker->releaseLock($dbConnection, $postgresLockId);
Changelog
Detailed changes for each release are documented in the CHANGELOG.md.
License
PHP DB Locker
package is open-sourced software licensed under the MIT license by Anton Komarev.
🌟 Stargazers over time
About CyberCog
CyberCog is a Social Unity of enthusiasts. Research the best solutions in product & software development is our passion.