PHPackages                             team-a/lock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. team-a/lock

ActiveLibrary[Database &amp; ORM](/categories/database)

team-a/lock
===========

Exclusive &amp; Read/Write locking based on MySQL Locking Service.

1.2.1(5y ago)11162MITPHPPHP ^7.1

Since Jun 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/team-a-pro/lock)[ Packagist](https://packagist.org/packages/team-a/lock)[ RSS](/packages/team-a-lock/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (5)Used By (0)

lock
====

[](#lock)

Exclusive &amp; Read/Write locking based on MySQL Locking Service

Requirements
------------

[](#requirements)

- php &gt;= 7.1
- PDO extension

Need to install the locking service UDFs as described in MySQL docs:

Install via Composer
--------------------

[](#install-via-composer)

`composer require team-a/lock:^1.2.0`

Examples
--------

[](#examples)

- Inject PDO instance promise. You can create lazy instance of PDO.

```
    $serviceManager = $this->getServiceManager();

    AbstractDb::setPdoPromise(
        function() use ($serviceManager) : \PDO
        {
            return $serviceManager->getPDO();
        }
    );
```

- Define and use your own lock class based on TeamA\\Lock\\AbstractDBExclusive or TeamA\\Lock\\AbstractDBExtended.
- Exclusive lock example:

```
    class Point extends AbstractDbExclusive
    {
        protected function __construct(
            int      $providerId,
            ? string $providerPointId,
            ? string $providerPointEssentialId
        )
        {
            parent::__construct([
                $providerId, $providerPointId, $providerPointEssentialId
            ]);
        }
    }

    /* ... */

    $pointLock = new Point($pId, $pPointId, null);

    try {
        $pointLock->lock();

        $this->_db->beginTransaction();

        // do smth.

        $this->_db->commit();

        return true;

      } catch (TeamA\Lock\TimeoutException $e) {

         return false;

      } catch (\Exception $e) {

         $this->_db->rollback();
         throw $e;

      } finally {

         $pointLock->releaseIfLocked();

      }
```

- Read/Write locking example:

```
    class GeoBinding extends AbstractDbExtended
    {
        public function __construct(int $departureProviderId)
        {
            parent::__construct(func_get_args());
        }
    }

    /* ... */

    $lock = new GeoBinding(static::_getProviderId());

    try {
        $lock->lockWrite();

        $this->_db->beginTransaction();

        // do smth.

        $this->_db->commit();

        return true;

    } catch (TeamA\Lock\TimeoutException $e) {

       return false;

    } catch (\Exception $e) {

       $this->_db->rollback();
       throw $e;

    } finally {

       $lock->release();

    }

    /* ... */

    $lock = new GeoBinding(static::_getProviderId());

    try {
        $lock->lockRead();

        $this->_db->beginTransaction();

        // do smth. else...

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~185 days

Total

4

Last Release

1973d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13346307?v=4)[team-a](/maintainers/team-a)[@team-a](https://github.com/team-a)

![](https://www.gravatar.com/avatar/ef601aa6404b912bfc6468af9c5377ae784fb249c6c3b0efadbc5746a0744768?d=identicon)[jadrovski](/maintainers/jadrovski)

---

Top Contributors

[![knifefencer](https://avatars.githubusercontent.com/u/51702513?v=4)](https://github.com/knifefencer "knifefencer (10 commits)")[![jadrovski](https://avatars.githubusercontent.com/u/5039759?v=4)](https://github.com/jadrovski "jadrovski (2 commits)")

---

Tags

lockinglock

### Embed Badge

![Health badge](/badges/team-a-lock/health.svg)

```
[![Health](https://phpackages.com/badges/team-a-lock/health.svg)](https://phpackages.com/packages/team-a-lock)
```

###  Alternatives

[malkusch/lock

Mutex library for exclusive code execution.

9459.6M27](/packages/malkusch-lock)[arvenil/ninja-mutex

Simple to use mutex implementation that can use flock, memcache, memcached, mysql or redis for locking

1873.7M27](/packages/arvenil-ninja-mutex)[stefangabos/zebra_session

A drop-in replacement for PHP's default session handler which stores session data in a MySQL database, providing better performance, better security and protection against session fixation and session hijacking

174112.1k2](/packages/stefangabos-zebra-session)[mpyw/laravel-database-advisory-lock

Advisory Locking Features of Postgres/MySQL/MariaDB on Laravel

2860.5k](/packages/mpyw-laravel-database-advisory-lock)[sofa/model-locking

Pseudo pessimistic model locking with broadcasted events for Laravel Eloquent ORM.

5048.0k](/packages/sofa-model-locking)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2919.9k](/packages/voku-session2db)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
