PHPackages                             kmuenkel/parallel-collection - 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. kmuenkel/parallel-collection

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

kmuenkel/parallel-collection
============================

A Laravel wrapper for amphp/amp offering a Collection Macro that performs parallel processing

v1.0.11(1825y ago)33.9kMITPHPPHP &gt;=7.4

Since Mar 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kmuenkel/parallel-collection)[ Packagist](https://packagist.org/packages/kmuenkel/parallel-collection)[ Docs](https://github.com/kmuenkel/paralle;-collection)[ RSS](/packages/kmuenkel-parallel-collection/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (14)Used By (0)

ParallelCollection
==================

[](#parallelcollection)

A Laravel wrapper for [amphp/amp](https://github.com/amphp/amp) offering a Collection Macro that performs parallel processing.

There is a similar package called [spatie/laravel-collection-macros](https://github.com/spatie/laravel-collection-macros#parallelmap) that attempts this, but falls short when the parallel Closure attempts to leverage Laravel abstractions or Model instances. The problem is that, similar to isolated PhpUnit tests, the App needs to be reinitialized when the Closure is underialized for execution. Additionally, serializing and unserializing Model classes is not a straight-forward process, because there are database connections that need to be reestablished. Laravel has already solved this problem though, in the context of serializing Closures for Queued Jobs. So both issues are answerable using existing traits from the framework.

Note that although AmPhp this offers true parallel processing, the parent thread still needs to wait for all children to resolve before closing out. Similar to forking, this seems to be a limitation of Php itself, that if a child task is permitted to resolve *after* the parent closes, either the parent will attempt to terminate the child prematurely, or the child thread will never be instructed to release its resources after it's done executing, resulting in a zombie process. If the intent is to fire a process intended to resolve later and not make the parent wait around for it, you'll still have to use something like a [Queued Job](https://laravel.com/docs/9.x/queues). However, a combination of a queuing and this parallel processor can get the best of both worlds and be extremely performant.

Usage
-----

[](#usage)

### Parallel Closures

[](#parallel-closures)

If the items to be handled in parallel are themselves closures, no special treatment is needed.

```
$process1 = function () {
    sleep(5);   //Simulate taking a long time to handle the item
    return 'perform some long process';
};

$process2 = function () {
    sleep(5);   //Simulate taking a long time to handle the item
    return 'perform another long process';
};

$items = compact('process1', 'process1');

$before = now();
$results = collect($items)->mapToParallel()->toArray();
$after = now();

$elapsedTime = $after->diffInSeconds($before);
print_r(compact('results', 'elapsedTime'));

/**
 * Array:
 * (
 *    "results" => Array
 *    (
 *       ["process1"] => 'perform some long process'
 *       ["process2"] => 'perform another long process'
 *    )
 *    "elapsedTime" => 5
 * )
 */
```

### Parallel items with handler

[](#parallel-items-with-handler)

If your items are not closures, but instead need one to act on them, the example would look like this:

```
$items = ['Hello', 'World'];
$handler = function (string $item) {
    sleep(5);   //Simulate taking a long time to handle the item

    return $item;
};

$before = now();
$results = collect($items)->mapToParallel($handler)->toArray();
$after = now();

$elapsedTime = $after->diffInSeconds($before);
print_r(compact('results', 'elapsedTime'));

/**
 * Array:
 * (
 *    "results" => Array
 *    (
 *       [0] => 'Hello'
 *       [1] => 'World'
 *    )
 *    "elapsedTime" => 5
 * )
 */
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

Established project with proven stability

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

Total

12

Last Release

666265d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/86619ba927c0055375588f0c21d6d0d89be6a74e4a2cb98558062c852ebe5c66?d=identicon)[kmuenkel](/maintainers/kmuenkel)

---

Top Contributors

[![kmuenkel](https://avatars.githubusercontent.com/u/17931045?v=4)](https://github.com/kmuenkel "kmuenkel (18 commits)")

---

Tags

asynchronouspromiseperformancecollectionparallel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kmuenkel-parallel-collection/health.svg)

```
[![Health](https://phpackages.com/badges/kmuenkel-parallel-collection/health.svg)](https://phpackages.com/packages/kmuenkel-parallel-collection)
```

###  Alternatives

[amphp/amp

A non-blocking concurrency framework for PHP applications.

4.4k123.4M322](/packages/amphp-amp)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

91943.6M138](/packages/revolt-event-loop)[amphp/parallel

Parallel processing component for Amp.

84746.2M74](/packages/amphp-parallel)[icicleio/icicle

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

1.1k150.9k14](/packages/icicleio-icicle)[recoil/react

Integrate Recoil with ReactPHP.

32274.4k12](/packages/recoil-react)[orisai/scheduler

Cron job scheduler - with locks, parallelism and more

4037.1k4](/packages/orisai-scheduler)

PHPackages © 2026

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