PHPackages                             danil-kashin/worker - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. danil-kashin/worker

ActiveLibrary[Queues &amp; Workers](/categories/queues)

danil-kashin/worker
===================

Abstract tick-based worker with signal handling support.

v1.0.1(2mo ago)0491BSD-3-ClausePHPPHP ^8.3

Since Mar 26Pushed 2mo agoCompare

[ Source](https://github.com/KashinDanil/Worker)[ Packagist](https://packagist.org/packages/danil-kashin/worker)[ RSS](/packages/danil-kashin-worker/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (2)Versions (3)Used By (1)

Worker
======

[](#worker)

A minimal PHP library for building tick-based background workers with signal handling.

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

[](#requirements)

- PHP 8.3+
- Extension: `ext-pcntl`

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

[](#installation)

```
composer require danil-kashin/worker
```

Usage
-----

[](#usage)

Extend the `Worker` class and implement the `tick()` method:

```
use DanilKashin\Worker\Worker;

class MyWorker extends Worker
{
    protected function tick(): void
    {
        // Your logic runs here on every tick
    }
}

(new MyWorker())->run();
```

### Limiting ticks

[](#limiting-ticks)

Pass `maxTicks` to run the worker a fixed number of times and exit — useful for cron jobs or batch processing:

```
(new MyWorker(maxTicks: 100))->run();
```

Override `getDefaultMaxTicks()` if the limit is intrinsic to the worker class itself:

```
protected function getDefaultMaxTicks(): ?int
{
    return 100;
}
```

`null` (the default) means the worker runs indefinitely until a stop signal is received.

### Tick interval

[](#tick-interval)

Override `getTickIntervalMs()` to control how long the worker sleeps between ticks (default: 100ms):

```
protected function getTickIntervalMs(): int
{
    return 500; // 500ms between ticks
}
```

### Graceful shutdown

[](#graceful-shutdown)

The worker handles `SIGTERM` and `SIGINT` automatically — it finishes the current tick before stopping.

Override `onStopping()` to run cleanup logic before the process exits:

```
protected function onStopping(): void
{
    // flush buffers, close connections, etc.
}
```

If you need to react to a stop signal mid-tick (e.g. to break out of an inner loop early):

```
protected function tick(): void
{
    foreach ($this->getItems() as $item) {
        if ($this->shouldStop()) {
            break;
        }

        $this->process($item);
    }
}
```

### Error handling

[](#error-handling)

Exceptions thrown inside `tick()` are caught, written to `stderr`, and the worker continues running. Override `handleTickError()` to customize this behavior:

```
protected function handleTickError(Throwable $e): void
{
    // custom error handling
}
```

Running via CLI
---------------

[](#running-via-cli)

The package ships with `bin/run_worker`, which instantiates and runs any `Worker` subclass by its fully qualified class name. Constructor parameters are passed as `--name=value` flags.

```
vendor/bin/run_worker "App\Workers\MyWorker"
```

Required constructor parameters without defaults will cause the script to fail with a clear error if omitted.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance83

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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 ~3 days

Total

2

Last Release

87d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/808cc658e54eb99caa9573723ab97993e9fcd90d2b6cd0940a1ba7eb8950f8cf?d=identicon)[KashinDanil](/maintainers/KashinDanil)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/danil-kashin-worker/health.svg)

```
[![Health](https://phpackages.com/badges/danil-kashin-worker/health.svg)](https://phpackages.com/packages/danil-kashin-worker)
```

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.5M29](/packages/league-geotools)[illuminate/bus

The Illuminate Bus package.

6045.5M505](/packages/illuminate-bus)[uecode/qpush-bundle

Asynchronous processing for Symfony using Push Queues

1672.5M2](/packages/uecode-qpush-bundle)[jayazhao/think-queue-rabbitmq

为 ThinkPHP5.1 队列增加 RabbitMQ 驱动

141.5k](/packages/jayazhao-think-queue-rabbitmq)

PHPackages © 2026

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