PHPackages                             hds-solutions/parallel-sdk - 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. hds-solutions/parallel-sdk

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

hds-solutions/parallel-sdk
==========================

SDK to implement parallel php extension

3.0.0(10mo ago)82.7k1[2 issues](https://github.com/hschimpf/parallel-sdk/issues)MITPHPPHP ^8.2CI passing

Since Feb 23Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/hschimpf/parallel-sdk)[ Packagist](https://packagist.org/packages/hds-solutions/parallel-sdk)[ RSS](/packages/hds-solutions-parallel-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (16)Used By (0)

Parallel SDK
============

[](#parallel-sdk)

An implementation of [krakjoe/parallel](https://github.com/krakjoe/parallel) PHP extension.

[![Latest stable version](https://camo.githubusercontent.com/a423ad294da9803ce4bf023e682f41a9a4e51c1f8c2267c02c10baa287b40f0e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6864732d736f6c7574696f6e732f706172616c6c656c2d73646b3f7374796c653d666c61742d737175617265266c6162656c3d6c617465737426636f6c6f723d303039324342)](https://github.com/hschimpf/parallel-sdk/releases/latest)[![License](https://camo.githubusercontent.com/eb51f35201bff5746206af685891ba4aaa77103789a20efc3df5fd99485bf1ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6864732d736f6c7574696f6e732f706172616c6c656c2d73646b3f7374796c653d666c61742d73717561726526636f6c6f723d303039363634)](https://github.com/hschimpf/parallel-sdk/blob/main/LICENSE)[![Total Downloads](https://camo.githubusercontent.com/da558f5aad7b6604dccd501dfb9bc1b47be2af2c37877e5c6f571e2c6231e6e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6864732d736f6c7574696f6e732f706172616c6c656c2d73646b3f7374796c653d666c61742d73717561726526636f6c6f723d373437343734)](https://packagist.org/packages/hds-solutions/parallel-sdk)[![Monthly Downloads](https://camo.githubusercontent.com/ecc2768b27958d15851fea7b857b0464bcf8dd7d8106001397c79ce5341ed76b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6864732d736f6c7574696f6e732f706172616c6c656c2d73646b3f7374796c653d666c61742d73717561726526636f6c6f723d373437343734266c6162656c)](https://packagist.org/packages/hds-solutions/parallel-sdk)[![Required PHP version](https://camo.githubusercontent.com/d1b7d98f487077c79496801b2b62ba2167cd1e71e410b332726eabacc3b677e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6864732d736f6c7574696f6e732f706172616c6c656c2d73646b2f7068703f7374796c653d666c61742d73717561726526636f6c6f723d303036343936266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/hds-solutions/parallel-sdk)

[![PHP 8.2](https://camo.githubusercontent.com/aa0cd322666e223d7edcf99886c8a4d39ef06aeefc6ac8f564e94e92a2e55a60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6864732d736f6c7574696f6e732f706172616c6c656c2d73646b2f6c696e75782d7068702d382e322e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d504850253230382e32)](https://github.com/hschimpf/parallel-sdk/actions/workflows/linux-php-8.2.yml)[![PHP 8.3](https://camo.githubusercontent.com/a8d6805f494dda3219fe5d7f6dac44cd7b29902c2cddbd7fc74e57fb2b4dc972/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6864732d736f6c7574696f6e732f706172616c6c656c2d73646b2f6c696e75782d7068702d382e332e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d504850253230382e33)](https://github.com/hschimpf/parallel-sdk/actions/workflows/linux-php-8.3.yml)[![PHP 8.4](https://camo.githubusercontent.com/af0cfa819c847f0103cab4fa7f26a87a8b2694f08c105efee870646a6b3f7edf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6864732d736f6c7574696f6e732f706172616c6c656c2d73646b2f6c696e75782d7068702d382e342e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d504850253230382e34)](https://github.com/hschimpf/parallel-sdk/actions/workflows/linux-php-8.4.yml)

This library is designed to work even if the `parallel` extension isn't available. In that case, the tasks will be executed un sequential order. That allow that your code can be deployed in any environment, and if `parallel` is enabled you will get the advantage of parallel processing.

Installation
------------

[](#installation)

### Dependencies

[](#dependencies)

You need these dependencies to execute tasks in parallel.

- PHP &gt;= 8.2 with ZTS enabled
- parallel PECL extension *(v1.2.5 or higher)*

Parallel extension documentation can be found on .

### Through composer

[](#through-composer)

```
composer require hds-solutions/parallel-sdk
```

Usage
-----

[](#usage)

You should set the bootstrap file for the parallel threads. Setting the composer's autoloader is enough.

```
// check if extension is loaded to allow deploying even in environments where parallel isn't installed
if (extension_loaded('parallel')) {
    // set the path to composer's autoloader
    parallel\bootstrap(__DIR__.'/vendor/autoload.php');
}
```

Behind the scenes, the parallel extension creates an empty Runtime *(thread)* where the tasks are executed. Every Runtime is a clean, empty, isolated environment without any preloaded classes, functions, or autoloaders from the parent thread/process. This isolation ensures that each runtime starts with a minimal footprint. See references [\#1](#references) and [\#2](#references) for more info.

Then you define a `Worker` that will process the tasks. There are two options:

1. Using an anonymous function as a `Worker`.
2. Creating a class that extends from `ParallelWorker` and implements the `process()` method.

Then you can schedule tasks to run in parallel using `Scheduler::runTask()` method.

### Bootstrap a Laravel app

[](#bootstrap-a-laravel-app)

Since ZTS is only available on the cli, you should set the bootstrap file for parallel threads in the `artisan` file.

```
#!/usr/bin/env php
