PHPackages                             illchuk/illchuk-locker - 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. [Caching](/categories/caching)
4. /
5. illchuk/illchuk-locker

ActiveLibrary[Caching](/categories/caching)

illchuk/illchuk-locker
======================

Prevent an action for some long amount of time. Hours, days, months, years.

v0.1(8y ago)079MITPHPPHP &gt;=5.6

Since Nov 24Pushed 8y ago1 watchersCompare

[ Source](https://github.com/dillchuk/illchuk-locker)[ Packagist](https://packagist.org/packages/illchuk/illchuk-locker)[ Docs](https://github.com/dillchuk/illchuk-locker)[ RSS](/packages/illchuk-illchuk-locker/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

IllchukLock
===========

[](#illchuklock)

[![Build Status](https://camo.githubusercontent.com/edbc964fa1b70342d55c8f94609f8b11cd6b024411c8c8091af0c178d4173bc2/68747470733a2f2f7472617669732d63692e6f72672f64696c6c6368756b2f696c6c6368756b2d6c6f636b65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dillchuk/illchuk-locker)

**Now with 100% code coverage.**

Prevent an action for some amount of time. Hours, day, months, years, anything. Allows for multiple locks (e.g. 100/day) and clearing/releasing a lock just made. And it works just like it should, every single lock lasts exactly how long you specify and is taken atomically.

### Installation

[](#installation)

1. In `application.config.php`, add as follows:

```
'modules' => [..., 'IllchukLock', ...];
```

2. Import into your database `data/illchuk_lock.sql`:

```
CREATE TABLE IF NOT EXISTS `illchuk_lock` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `key` varchar(255) NOT NULL UNIQUE KEY,
  `end_datetime` DATETIME NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `illchuk_lock` ADD INDEX (`end_datetime`);
```

### To Use

[](#to-use)

Either you get the lock or you don't.

```
// in controller
$locker = $this->getServiceLocator()->get('IllchukLock');

// term?
$term = new DateTimeUnit(2, 'weeks'); // or
$term = new DateTimeEnd(new DateTime('+2 weeks'));

if ($locker->takeLock('BiWeeklyReport', $term)) {
    // lock is taken atomically, made for 2 weeks: safe to do your work
}
else {
    // locked from before: leave it alone & perhaps try again later
}

/**
 * N.B. May throw \IllchukLock\Exception\PhantomLockException, when
 * lock is reported to be set but upon verification step is actually not.
 * This is truly exceptional and shouldn't be just thrown aside.
 */
```

### Allow Multiple Locks

[](#allow-multiple-locks)

You can allow any number of locks e.g. 'lock1' =&gt; 5/hour, 'lock2' =&gt; 100/day. Here's how:

```
// copy IllchukLock.global.php to your config/autoload/
$locker = [
// ...
    'adapter_class' => 'IllchukLock\Adapter\DbMultiple', // was Adapter\Db
// ...
]
$regexCounts = [
    /**
     * E.g. You can create 3 'do-stuff' locks before the lock can't be taken.
     * Those not matching here are allowed the usual 1.
     */
    '/^do-stuff$/' => 3
];

// in controller
$locker = $this->getServiceLocator()->get('IllchukLock');
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // YES
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // YES
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // YES
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // FALSE
// ...
// A DAY LATER
$locker->takeLock('do-stuff', new DateTimeUnit(1, 'day')); // YES
```

### Clearing Locks

[](#clearing-locks)

```
$locker = $this->getServiceLocator()->get('IllchukLock');
$handle = $locker->takeLock('year-end', new DateTimeUnit(1, 'year')); // YES
$locker->takeLock('year-end', new DateTimeUnit(1, 'year')); // FALSE
if ($whoopsBackingOut) {
    $locker->clearLock($handle);
}
$locker->takeLock('year-end', new DateTimeUnit(1, 'year')); // YES
```

### Lock with APC

[](#lock-with-apc)

For something more quick-n-dirty, use APC locking. This is adequate for short-term throttling with the usual caveats regarding APC persistence (e.g. some other part of your app might flush the entire cache, a PHP restart, out of memory).

N.B. If `takeLock()` fails, don't try to `sleep()` it out; that won't work for some reason to do with how `apc_add()` works. Instead, handle the no-lock condition then try again next request.

```
// copy illchuklock.global.php to your config/autoload/
$locker = [
// ...
    'adapter_class' => 'IllchukLock\Adapter\Apc', // was Adapter\Db
// ...
]

// from service manager
$locker = $container->get('IllchukLock');

// alternatively, a shortcut factory that doesn't require config
$locker = $container->get('illchuk_lock_apc');
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

3140d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/36c24140c7709b9015bdb1d58f0937b0c72801a63ae4b32cc18ba3f71a1eaa23?d=identicon)[dillchuk](/maintainers/dillchuk)

---

Top Contributors

[![dillchuk](https://avatars.githubusercontent.com/u/11740626?v=4)](https://github.com/dillchuk "dillchuk (25 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/illchuk-illchuk-locker/health.svg)

```
[![Health](https://phpackages.com/badges/illchuk-illchuk-locker/health.svg)](https://phpackages.com/packages/illchuk-illchuk-locker)
```

###  Alternatives

[zf-commons/zfc-user

A generic user registration and authentication module for ZF2. Supports Zend\\Db and Doctrine2.

4851.1M71](/packages/zf-commons-zfc-user)[zf-commons/zfc-base

A set of genetic (abstract) classes which are commonly used across multiple modules.

1441.1M25](/packages/zf-commons-zfc-base)[stroker/cache

Provides a full page cache solution for Laminas

6044.8k](/packages/stroker-cache)[socalnick/scn-social-auth

Uses the HybridAuth PHP library to Enable authentication via Google, Facebook, Twitter, Yahoo!, etc for the ZfcUser ZF2 module.

21674.9k3](/packages/socalnick-scn-social-auth)

PHPackages © 2026

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