PHPackages                             yidas/worker-dispatcher - 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. yidas/worker-dispatcher

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

yidas/worker-dispatcher
=======================

PHP multi-processing task dispatcher with managing workers

1.0.0(5y ago)68951MITPHPPHP &gt;=5.4

Since Jul 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/yidas/php-worker-dispatcher)[ Packagist](https://packagist.org/packages/yidas/worker-dispatcher)[ Docs](https://github.com/yidas/php-worker-dispatcher)[ RSS](/packages/yidas-worker-dispatcher/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

 [ ![](https://camo.githubusercontent.com/e331c9b89ef09fa1b8b98af2ae68dbd2e88d1dba522f0bf653292a94b3b28c37/68747470733a2f2f7777772e7068702e6e65742f696d616765732f6c6f676f732f7068702d6c6f676f2d6269676765722e706e67) ](https://www.php.net/)

PHP Worker Dispatcher
=====================

[](#php-worker-dispatcher)

PHP multi-processing task dispatcher with managing workers

[![Latest Stable Version](https://camo.githubusercontent.com/1fd041986e2ae0a72ef395a626a8a957fa088672ef691eedcca5bf8041804b05/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f776f726b65722d646973706174636865722f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/worker-dispatcher)[![License](https://camo.githubusercontent.com/3b417e6a05b5fbf373f949ac19b44335b0ba26d81f595ecb78b79382221f3b33/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f776f726b65722d646973706174636865722f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/worker-dispatcher)

Features
--------

[](#features)

- ***Multi-Processing** implementation on native PHP-CLI*
- ***Tasks Dispatching** to each worker process*
- ***Elegant Interface** for setup and use*

---

OUTLINE
-------

[](#outline)

- [Demonstration](#demonstration)
- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Option](#option)
        - [callbacks.process](#callbacksprocess)
        - [callbacks.task](#callbackstask)

---

DEMONSTRATION
-------------

[](#demonstration)

Use multi-processing to dispatch tasks with generating workers based on CPU cores:

```
\yidas\WorkerDispatcher::run([
    'tasks' => ["R4NEJ1", "F5KH83", "..."],
    'callbacks' => [
        // The callback is for each forked process with decentralized tasks
        'task' => function ($config, $workderId, $task) {
            // $task is one of the `tasks` assigned to each worker, ex. "F5KH83" for $workderId is 2
            $token = $task;
            $result = file_get_contents("https://example/v1/register-by-token/{$token}");
        },
    ],
]);
```

Use multi-processing to digest jobs from queue:

```
\yidas\WorkerDispatcher::run([
    'tasks' => false,
    'callbacks' => [
        // The callback is for each forked process
        'process' => function ($config, $workderId, $task) {
            // Get and handle each job from queue in inifite loop (You need to define your own function)
            while (true) {
                $result = handleOneJobFromQueue();
                if ($result === null) {
                    break;
                }
            }
        },
    ],
]);
```

---

INTRODUCTION
------------

[](#introduction)

This library is implemented by PHP PCNTL control, which provides a main PHP-CLI to fork multiple child processes to share tasks, and even can use for high concurrency application with infinite loop setting.

[![](https://raw.githubusercontent.com/yidas/php-worker-dispatcher/master/img/introduction.png)](https://raw.githubusercontent.com/yidas/php-worker-dispatcher/master/img/introduction.png)

> Since PHP has no shared variables or queue mechanism natively, if you don’t have an external job queue, this library provides a task average dispatcher to simply solve the core distributed processing problem.

---

REQUIREMENTS
------------

[](#requirements)

This library requires the following:

- PHP [PCNTL](https://www.php.net/manual/en/pcntl.installation.php)
- PHP CLI 5.4.0+

---

INSTALLATION
------------

[](#installation)

Run Composer in your project:

```
composer require yidas/worker-dispatcher ~1.0.0

```

Then you could use the class after Composer is loaded on your PHP project:

```
require __DIR__ . '/vendor/autoload.php';

use yidas\WorkerDispatcher;
```

---

USAGE
-----

[](#usage)

Calling the `run()` method statically with options as argument, WorkerDispatcher will start to dispatch tasks (if any), and then fork the number of workers according to the environment or settings, and wait for all forked processes to complete or terminate the main process.

The setting example with all options is as following:

```
\yidas\WorkerDispatcher::run([
    'debug' => true,
    'workers' => 4,
    'config' => ['uri' => "/v1/resource"],
    'tasks' => ["R4NEJ1", "F5KH83", "..."],
    'callbacks' => [
        'process' => function ($config, $workerId, $tasks) {
            echo "The number of tasks in forked process - {$workerId}: " . count($tasks[$workerId - 1]) . "\n";
        },
        'task' => function ($config, $workerId, $task) {
            echo "Forked process - {$workerId}: Request to {$config['uri']} with token {$task}\n";
        },
    ],
]);
```

### Options

[](#options)

OptionTypeDeafultDescriptiondebugbooleanfalseDebug modeworkersinteger(auto)The number of workers(processes) to fork.
(The default is the same as the number of CPU cores)configmultitypenullThe custom variable used to bring in the callback functiontasksmultitypearrayFor dispatching to each forked process.  *- Array: Each value of array will be dispatched to all forked processes.
- Integer: The number of loops dispatched to all forked processes.
- false: Perform finite loop.*[callbacks.process](#callbacksprocess)callablenulCallback function called after each forked process is created[callbacks.task](#callbackstask)callablenulCallback function called in each task loop of each forked process#### callbacks.process

[](#callbacksprocess)

Callback function called after each forked process is created

```
function (multitype $config, integer $workerId, array $tasks)
```

ArgumentTypeDeafultDescription$configmultitypenullThe custom variable used to bring in the callback function$workerIdinteger(auto)The sequence number of the worker(processes) in current function (Start from 1)$tasksmultitypearrayTasks array list for the worker(processes) in current function#### callbacks.task

[](#callbackstask)

Callback function called in each task loop of each forked process

```
function (multitype $config, integer $workerId, multitype $task)
```

ArgumentTypeDeafultDescription$configmultitypenullThe custom variable used to bring in the callback function$workerIdinteger(auto)The sequence number of the worker(processes) in current function (Start from 1)$tasksmultitypearrayThe value of each tasks array list for each worker(processes) in current function

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

2112d ago

### Community

Maintainers

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

---

Top Contributors

[![yidas](https://avatars.githubusercontent.com/u/12604195?v=4)](https://github.com/yidas "yidas (9 commits)")

---

Tags

multiprocessingpcntlphpphp-clitask-dispatcherworkersphptaskmultiprocessingworkerpcntlworker-manageworker-dispatcher

### Embed Badge

![Health badge](/badges/yidas-worker-dispatcher/health.svg)

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

###  Alternatives

[dusterio/laravel-aws-worker

Run Laravel (or Lumen) tasks and queue listeners inside of AWS Elastic Beanstalk workers

3105.7M](/packages/dusterio-laravel-aws-worker)[qxsch/worker-pool

Runs tasks in a parallel processing workerpool.

108325.7k1](/packages/qxsch-worker-pool)[iron-io/iron_worker

Client library for IronWorker (multi-language worker platform that runs tasks in the background, in parallel, and at scale.)

57208.5k1](/packages/iron-io-iron-worker)[yidas/codeigniter-queue-worker

CodeIgniter 3 Queue Worker Management Controller

9665.2k2](/packages/yidas-codeigniter-queue-worker)[tarantool/queue

PHP bindings for Tarantool Queue.

64136.2k4](/packages/tarantool-queue)

PHPackages © 2026

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