PHPackages                             php-strict/cooperative-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. php-strict/cooperative-worker

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

php-strict/cooperative-worker
=============================

Class for executing jobs from one list in several processes

041PHP

Since Jun 3Pushed 2y ago1 watchersCompare

[ Source](https://github.com/php-strict/cooperative-worker)[ Packagist](https://packagist.org/packages/php-strict/cooperative-worker)[ RSS](/packages/php-strict-cooperative-worker/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Cooperative worker
==================

[](#cooperative-worker)

[![Software License](https://camo.githubusercontent.com/e1514dd3f2095dbf68a0008ae62a631142953ad2e86aa94c504343f2c2c191da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c2d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![Build Status](https://camo.githubusercontent.com/9d7eced909700013c72a539ed1859a2915b6c7594ff1c3af5e7014b2466f2de1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d7374726963742f636f6f70657261746976652d776f726b65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/php-strict/cooperative-worker)[![codecov](https://camo.githubusercontent.com/03b3fa9c4cf5f149bfe0c24559a8d5248867751fcda471d1b062db8166d61672/68747470733a2f2f636f6465636f762e696f2f67682f7068702d7374726963742f636f6f70657261746976652d776f726b65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/php-strict/cooperative-worker)[![Codacy Badge](https://camo.githubusercontent.com/5f546e1d8ed445d285e78e5504b01e1b8e6664233cbb0aade6e351c8158abe29/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6166353164376633323033383434303461306466656662323531316362663432)](https://www.codacy.com/gh/php-strict/cooperative-worker?utm_source=github.com&utm_medium=referral&utm_content=php-strict/cooperative-worker&utm_campaign=Badge_Grade)

Class for executing jobs from one list in several processes. Class not have mechanism to create processes, consumer must create it by self. Each separate process can create instance of class wich will work with shared storage without collisions. Temporary storage of jobs (queue) will be created in first instance of class and it be use all of instances.

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

[](#requirements)

- PHP &gt;= 7.1

Install
-------

[](#install)

Use class as standalone:

```
require 'CooperativeWorker.php';
use PhpStrict\CooperativeWorker\CooperativeWorker;
```

Install with [Composer](http://getcomposer.org):

```
composer require php-strict/cooperative-worker
```

Usage
-----

[](#usage)

Before (all jobs running through one process):

```
//$jobs - list of commands, files to processing, ...
$jobs = ['job 1', 'job 2', 'job 3', 'job 4', 'job 5'];

foreach ($jobs as $job) {
    echo 'Start job: ' . $job . PHP_EOL;
    //do some job
}
```

With cooperative worker:

cw.php

```
use PhpStrict\CooperativeWorker\CooperativeWorker;

$cw = new CooperativeWorker(
    function() {
        return ['job 1', 'job 2', 'job 3', 'job 4', 'job 5'];
    },
    function(string $job) {
        echo 'Start job: ' . $job . PHP_EOL;
        //do some job
    }
);
$cw->run();
```

cw.bat (on Windows using `start` command to create a two separate processes)

```
start php -f cw.php
start php -f cw.php
```

cw.sh (on Linux using `&` at the end of command to create a two separate processes)

```
php -f cw.php &
php -f cw.php &
```

using [ScriptRunner](https://github.com/php-strict/script-runner)

```
use PhpStrict\ScriptRunner\ScriptRunner;

//path_to_script, processes count (if omitted then system CPU cores count will be used)
$sr = new ScriptRunner('cw.php', 4);
$sr->run();
```

Processing images (log files, data files, etc.)

cw.php

```
use PhpStrict\CooperativeWorker\CooperativeWorker;

$cw = new CooperativeWorker(
    //returns array of images (with path to it) from dir
    function() {
        $images = glob('/path_to_images/*.jpg');
        array_walk(
            $images,
            function(&$val, $key, $path) {
                $val = $path . '/' . $val;
            },
            '/path_to_images'
        );
        return $images;
    },
    function(string $image) {
        echo 'Processing image: ' . $image . PHP_EOL;
        //do some image operation (resizing, cropping, etc.)
    }
);
$cw->run();
```

Tests
-----

[](#tests)

To execute the test suite, you'll need [Codeception](https://codeception.com/).

```
vendor/bin/codecept run
```

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f404fa292f952ba0429cfe11f608e982e0d9d645f2ac864c53abee7f71dff2b?d=identicon)[enikeishik](/maintainers/enikeishik)

---

Top Contributors

[![enikeishik](https://avatars.githubusercontent.com/u/2239913?v=4)](https://github.com/enikeishik "enikeishik (42 commits)")

---

Tags

cooperativephpphp-libraryphp7

### Embed Badge

![Health badge](/badges/php-strict-cooperative-worker/health.svg)

```
[![Health](https://phpackages.com/badges/php-strict-cooperative-worker/health.svg)](https://phpackages.com/packages/php-strict-cooperative-worker)
```

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.6M31](/packages/league-geotools)[illuminate/bus

The Illuminate Bus package.

6046.3M542](/packages/illuminate-bus)[uecode/qpush-bundle

Asynchronous processing for Symfony using Push Queues

1672.5M2](/packages/uecode-qpush-bundle)[belvg/module-sqs

N/A

1544.6k](/packages/belvg-module-sqs)[bsidev/bitrix-queue

Queues for Bitrix CMS

232.8k](/packages/bsidev-bitrix-queue)[lelivrescolaire/sqs-bundle

Communicate with an SQS queue from inside your symfony 2 application.

109.6k](/packages/lelivrescolaire-sqs-bundle)

PHPackages © 2026

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