PHPackages                             mehr-als-nix/parallel - 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. mehr-als-nix/parallel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mehr-als-nix/parallel
=====================

This package is a port of PhpDumentor/Parallel

v1.0.0(8y ago)7797.5k↑17.9%1MITPHP

Since Dec 10Pushed 7y ago2 watchersCompare

[ Source](https://github.com/MehrAlsNix/Parallel)[ Packagist](https://packagist.org/packages/mehr-als-nix/parallel)[ RSS](/packages/mehr-als-nix-parallel/feed)WikiDiscussions master Synced 1mo ago

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

Parallel
========

[](#parallel)

This is a library for introducing Parallelization into your project. See the `example.php` file for an example how to use this library.

Theory of Operation
-------------------

[](#theory-of-operation)

This library will enable the developer to execute a given amount of tasks (workers) in parallel. This is achieved by adding workers onto a manager, optionally defining how many processes to run simultaneously and then execute the manager.

Under Linux this library will try to detect the number of processors and allow a maximum number of processes to run equal to the number of processors. If this cannot be determined or the user is running Windows then a default of 2 is used.

Requirements and graceful degradation
-------------------------------------

[](#requirements-and-graceful-degradation)

Parallelization has several requirements. But to allow distribution, without adding several requirements to your application, will this library execute the given tasks in serie if the requirements are not met. And throw a E\_USER\_NOTICE php error that explains to the user that dependencies are missing.

The requirements for this library are:

- A \*NIX compatible operating system
- Scripts must not run from an apache module
- the PCNTL PHP extension ()

Workers
-------

[](#workers)

Workers are basically wrappers around callback functions or methods. As such you can use anything in your existing project and parallelize it.

Do note that each parallel process is a duplicate of the original. This means that, for example, if you pass an object (or other reference) and change that, that the changes that you have made do not carry over to the caller.

The return value of the given callback is stored as result on the worker and can be read using the `getResult()` method.

Any exception that is thrown will result in an error, where the `getReturnCode()`method will return the exception code (be warned: this may be 0!) and the `getError()` method will return the exception message.

Errors and exceptions
---------------------

[](#errors-and-exceptions)

if a task throws an exception it is caught and registered as an error. The exception's code is used as error number, where the message is used as error message.

By using this, instead of dying, you can continue execution of the other parallel processes and handle errors yourself after all processes have been executed.

Examples
--------

[](#examples)

### Fluent interface

[](#fluent-interface)

```
use MehrAlsNix\Parallel\Manager;
use MehrAlsNix\Parallel\Worker;

$mgr = new Manager();
$mgr
  ->addWorker(new Worker(function() { sleep(1); return 'a'; }))
  ->addWorker(new Worker(function() { sleep(1); return 'b'; }))
  ->addWorker(new Worker(function() { sleep(1); return 'c'; }))
  ->addWorker(new Worker(function() { sleep(1); return 'd'; }))
  ->addWorker(new Worker(function() { sleep(1); return 'e'; }))
  ->execute();

/** @var Worker $worker */
foreach ($mgr as $worker) {
    var_dump($worker->getResult());
}

```

### Array interface

[](#array-interface)

```
use MehrAlsNix\Parallel\Manager;
use MehrAlsNix\Parallel\Worker;

$mgr = new Manager();
$mgr[] = new Worker(function() { sleep(1); return 'f'; });
$mgr[] = new Worker(function() { sleep(1); return 'g'; });
$mgr[] = new Worker(function() { sleep(1); return 'h'; });
$mgr[] = new Worker(function() { sleep(1); return 'i'; });
$mgr[] = new Worker(function() { sleep(1); return 'j'; });
$mgr->execute();

/** @var Worker $worker */
foreach ($mgr as $worker) {
    var_dump($worker->getResult());
}

```

TODO
----

[](#todo)

- Improve docs
- More intelligent process slots; currently only the oldest in a 'set' of slots is waited on but if this runs for a longer time then the other slots than those will not be filled as long as the first slot is occupied.
- Last parts of IPC (Inter-Process Communication), to be able to return information from Workers to the Manager.

    - STDOUT
    - STDERR

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% 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

3081d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/197f7436c47067343def1d182dd597dbd104774fe17071e0b983487dc3652fe8?d=identicon)[siad007](/maintainers/siad007)

---

Top Contributors

[![mvriel](https://avatars.githubusercontent.com/u/193704?v=4)](https://github.com/mvriel "mvriel (5 commits)")[![siad007](https://avatars.githubusercontent.com/u/2149445?v=4)](https://github.com/siad007 "siad007 (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mehr-als-nix-parallel/health.svg)

```
[![Health](https://phpackages.com/badges/mehr-als-nix-parallel/health.svg)](https://phpackages.com/packages/mehr-als-nix-parallel)
```

###  Alternatives

[parsecsv/php-parsecsv

CSV data parser for PHP

6885.7M38](/packages/parsecsv-php-parsecsv)[kyslik/column-sortable

Package for handling column sorting in Laravel 6.x

6485.6M21](/packages/kyslik-column-sortable)[sensiolabs/ansi-to-html

A library to convert a text with ANSI codes to HTML

2537.8M53](/packages/sensiolabs-ansi-to-html)[dflydev/dot-access-configuration

Given a deep data structure representing a configuration, access configuration by dot notation.

13414.5M4](/packages/dflydev-dot-access-configuration)[stfalcon/tinymce-bundle

This Bundle integrates TinyMCE WYSIWYG editor into a Symfony2 project.

2692.9M24](/packages/stfalcon-tinymce-bundle)[b13/container

Create Custom Container Content Elements for TYPO3

1823.1M63](/packages/b13-container)

PHPackages © 2026

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