bettergist/concurrency-helper

A super simple way to concurrently run many PHP instances.

v1.0.0 2021-01-30 16:29 UTC

This package is not auto-updated.

Last update: 2024-12-13 04:17:08 UTC


README

ConcurrencyHelper is a library for easily and efficiently running any callable via multiple parallel PHP instances.

It's aim is to substantially simplify massively parallelized operations.

Notable use cases include the Bettergist Collector project, which uses ConcurrencyHelper to massively parallize the downloads of every www.Packagist.org package, using 50-200 PHP processes.

This library requires the ext-pcntl extension.

https://github.com/bettergistco/ConcurrencyHelper

Usage

```php
$myParallelizedFunction = function (int $childNumber, array $packages, $optionalExtraParameter) {
echo "Thread $childNumber: " . implode(', ', $packages) . " of $optionalExtraParameter\n";

    sleep($childNumber * 1);

    echo "Finished Thread $childNumber.\n";
};

$states = [
'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado',
'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho',
];

$runner = new BettergistCollective\ConcurrencyHelper\ConcurrencyHelper();
$runner->concurrentlyRun($states, 6, $myParallelizedFunction, [count($states)]);
```

Installation

Via Composer

$ composer require phpexperts/conciseuuid

This library requires the ext-pcntl extension.

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ phpunit

Contributing

Please take a look at contributing.md if you want to make improvements.

Credits

  • Theodore R. Smith

License

MIT license. Please see the license file for more information.