PHPackages                             tourze/lock-service-bundle - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/lock-service-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/lock-service-bundle
==========================

Lock Service

1.0.1(5mo ago)019.3k15MITPHPCI passing

Since Apr 14Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/lock-service-bundle)[ Packagist](https://packagist.org/packages/tourze/lock-service-bundle)[ RSS](/packages/tourze-lock-service-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (25)Versions (8)Used By (15)

Lock Service Bundle
===================

[](#lock-service-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/fdff5f22dd22ea20d734f6872987e7fad602cf8596d95ac65244581b097da5b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f6c6f636b2d736572766963652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/lock-service-bundle)[![PHP Version](https://camo.githubusercontent.com/c64b967dbbd36e69f6ab39985b13ffddf0e50fdbe147bd970ab26ccb70560b7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f6c6f636b2d736572766963652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/lock-service-bundle)[![License](https://camo.githubusercontent.com/39ab4302622c873264de636ce1b4607fd7887f2366165e23b9db17432fa03e80/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f6c6f636b2d736572766963652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/lock-service-bundle)[![Build Status](https://camo.githubusercontent.com/55c13caaffc9a63b98dbf144822d42e5c8caad0a49904d99f00ac17063abe046/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f746f75727a652f6c6f636b2d736572766963652d62756e646c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/tourze/lock-service-bundle)[![Quality Score](https://camo.githubusercontent.com/5e2e6b4a6dda21dd39185d1dcdc43d238b0f0cb53640f44a40a72796efc61e4f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f6c6f636b2d736572766963652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/lock-service-bundle)[![Code Coverage](https://camo.githubusercontent.com/e3007d03821975ad7643b38e7ceaec27e13094b4c234da90b3b513504bd566c5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f746f75727a652f6c6f636b2d736572766963652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/lock-service-bundle)[![Total Downloads](https://camo.githubusercontent.com/e96e38fe0fd9e0f7b00574d29f06b3449a56c03e2d508ec1429b89c0b327348b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f6c6f636b2d736572766963652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/lock-service-bundle)

A flexible distributed lock service bundle for Symfony, supporting Redis Cluster, database, and file-based backends. Ideal for resource mutual exclusion and synchronization in high concurrency scenarios.

Features
--------

[](#features)

- Supports Redis Cluster, database, and file lock backends
- SmartLockStore for automatic backend switching
- Provides read/write locks, blocking locks, and multi-resource locking
- Seamless integration with Symfony ecosystem
- Easy to extend and customize

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

[](#requirements)

- PHP &gt;= 8.1
- Symfony &gt;= 6.4
- Redis, database, or file backend configured

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require tourze/lock-service-bundle
```

Quick Start
-----------

[](#quick-start)

```
use Tourze\LockServiceBundle\Service\LockService;

$lockService = ... // Get via dependency injection

// Blocking execution
$lockService->blockingRun('resource-key', function () {
    // Logic protected by lock
});

// Multi-resource locking
$lockService->blockingRun(['key1', 'key2'], function () {
    // Logic protected by multiple locks
});
```

Configuration
-------------

[](#configuration)

### Bundle Registration

[](#bundle-registration)

Add to your `bundles.php`:

```
return [
    // ... other bundles
    Tourze\LockServiceBundle\LockServiceBundle::class => ['all' => true],
];
```

### Environment Configuration

[](#environment-configuration)

Select lock type via `APP_LOCK_TYPE` environment variable:

- redis
- redis-cluster
- dbal
- flock

Example:

```
APP_LOCK_TYPE=redis
```

### Database Configuration

[](#database-configuration)

If using DBAL backend, the bundle automatically configures a dedicated `lock`connection with SQLite for testing. For production, configure your database connection in `doctrine.yaml`:

```
doctrine:
    dbal:
        connections:
            lock:
                driver: pdo_mysql
                host: '%database_host%'
                port: '%database_port%'
                dbname: '%database_name%'
                user: '%database_user%'
                password: '%database_password%'
```

Advanced Usage
--------------

[](#advanced-usage)

- Automatic backend switching via SmartLockStore
- Retry and wait mechanism for lock acquisition
- Read/write lock support (see RedisClusterStore)
- Extensible: implement `LockEntity` interface for custom lock resources

Entity Design
-------------

[](#entity-design)

This bundle provides a `LockEntity` interface for defining lock resources:

```
interface LockEntity {
    public function retrieveLockResource(): string;
}
```

Implement this interface for your business entities to enable fine-grained distributed locking.

Security
--------

[](#security)

This bundle provides secure distributed locking mechanisms:

- Thread-safe lock acquisition and release
- Automatic lock expiration to prevent deadlocks
- Resource isolation through unique lock keys
- Protection against race conditions in concurrent environments

### Security Considerations

[](#security-considerations)

- Use unique, unpredictable lock keys for sensitive resources
- Set appropriate lock timeouts to prevent resource starvation
- Monitor lock usage to detect potential abuse
- Use dedicated Redis/database instances for production environments

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details. Follow PSR standards and provide tests.

License
-------

[](#license)

MIT License

Changelog
---------

[](#changelog)

See CHANGELOG.md

###  Health Score

40

—

FairBetter than 87% of packages

Maintenance77

Regular maintenance activity

Popularity20

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~36 days

Recently: every ~47 days

Total

7

Last Release

173d ago

Major Versions

0.1.2 → 1.0.02025-10-31

### Community

Maintainers

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

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-lock-service-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-lock-service-bundle/health.svg)](https://phpackages.com/packages/tourze-lock-service-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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