• Stars
    star
    103
  • Rank 332,195 (Top 7 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🏃 Run multiple processes simultaneously

Parallel Process

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Run multiple Symfony\Process's at the same time.

giphy

Install

Via Composer

$ composer require graze/parallel-process

If you want to use Tables or Lines to output to the console, include:

$ composer require graze/console-diff-renderer

Usage

$pool = new Pool();
$pool->add(new Process('sleep 100'));
$pool->add(new Process('sleep 100'));
$pool->add(new Process('sleep 100'));
$pool->add(new Process('sleep 100'));
$pool->add(new ProcessRun(new Process('sleep 100')));
$pool->run(); // blocking that will run till it finishes

A Pool will run all child processes at the same time.

Priority Pool

A Priority pool will sort the runs to allow a prioritised list to be started. You can also limit the number of processes to run at a time.

$pool = new PriorityPool();
$pool->add(new Process('sleep 100'), [], 1);
$pool->add(new Process('sleep 100'), [], 0.1);
$pool->add(new Process('sleep 100'), [], 5);
$pool->add(new Process('sleep 100'), [], 10);
$pool->add(new CallbackRun(
    function () {
        return 'yarp';
    },
    [],
    2
);
$pool->run(); // blocking that will run till it finishes

Recursive Pools

You can add a Pool as a child to a parent pool. A Pool will act just like a standard run and hide the child runs.

If the parent is a PriorityPool, it will control all the child runs so that priorities and the max simultaneous configuration options still apply.

$pool = new Pool();
$pool->add(new Process('sleep 100'));
$pool2 = new Pool();
$pool2->add(new Process('sleep 100'));
$pool->add($pool2);
$pool->run(); // blocking that will run till it finishes

Display

You can output runs in a few different ways to the command line. These require the use of the package: graze/console-diff-renderer.

Table

Visual output of the parallel processes

$pool = new \Graze\ParallelProcess\PriorityPool();
for ($i = 0; $i < 5; $i++) {
    $time = $i + 5;
    $pool->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' => $time]);
}
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$table = new \Graze\ParallelProcess\Display\Table($output, $pool);
$table->run();

asciicast

Lines

Write the output of each process to the screen

$pool = new \Graze\ParallelProcess\PriorityPool();
$pool->setMaxSimultaneous(3);
for ($i = 0; $i < 5; $i++) {
    $time = $i + 5;
    $pool->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' . $time]);
}
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$lines = new \Graze\ParallelProcess\Display\Lines($output, $pool);
$lines->run();

asciicast

Testing

$ make test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

supervisor

đŸšĻ Process supervisor for PHP.
PHP
98
star
2

guzzle-jsonrpc

JSON-RPC 2.0 client for Guzzle
PHP
93
star
3

queue

📮 Flexible abstraction for working with queues in PHP.
PHP
49
star
4

telnet-client

☎ī¸ A telnet client written in PHP
PHP
48
star
5

dog-statsd

đŸļ DataDog StatsD Client
PHP
41
star
6

cucumber-rest-bdd

Behavioural testing suite for RESTful APIs
Ruby
35
star
7

docker-php-alpine

minimal (ish) php images in alpine
Shell
33
star
8

data-structure

Common data structures
PHP
12
star
9

sort

A collection of array sorting transforms and functions
PHP
12
star
10

docker-composer

đŸŽļ A small Docker image for composer.
Shell
11
star
11

dal

Data Access Layer
PHP
8
star
12

array-merger

Recursively merge arrays with custom value choosers
PHP
7
star
13

dynamark3-client

🖨ī¸ A Dynamark Communication Protocol 3 client, written in PHP
PHP
7
star
14

signal-counter

đŸšĻ Embedded Raspberry Pi system for counting, recording and submitting input signals
C
7
star
15

docker-sqs-local

Docker image with an SQS-compatible queue implementation for local development
Dockerfile
6
star
16

standards

⚖ The coding standards of the graze tech team.
PHP
6
star
17

formatter

đŸŽĸ Convert objects into arrays of data by applying processors, filters, and sorters.
PHP
6
star
18

morphism

Tool for parsing, extracting, and diffing mysqldump files
PHP
6
star
19

data-flow

🌊 Move and manipulate data from one location to another
PHP
5
star
20

gigya-client

Communications with Gigya's REST api
PHP
5
star
21

console-diff-renderer

Only write minimal changes to the console
PHP
5
star
22

silex-trailing-slash-handler

↩ī¸ Silex trailing slash routing handler.
PHP
5
star
23

tropopause

☁ī¸ a thin layer over troposphere to simplify boilerplate code
Python
4
star
24

hamcrest-test-listener

👂 A PHPUnit test listener for the hamcrest assertion library.
PHP
4
star
25

transient-fault-handler

Retry tasks that fail due to transient errors
PHP
4
star
26

skeleton-project

☠ A skeleton repository for Graze open source projects.
PHP
3
star
27

unicontroller-client

🖨ī¸ Domino Unicontroller client written in PHP
PHP
3
star
28

docker-bats

docker image for BATS
Shell
2
star
29

monolog-extensions

Additional handlers, formatters and processors for use with Monolog
PHP
2
star
30

golang-service

📝 Golang HTTP Service Handlers and Helpers
Go
2
star
31

config-validation

Validate your configuration
PHP
1
star
32

data-validator

🚔 Validate data, decoupled from your front end presentation.
PHP
1
star
33

wipotec-checkweigher-client

Wipotec checkweigher client written in PHP
PHP
1
star
34

pycmd-utils

Easy Shell Commands With Python
Python
1
star
35

blog

The graze tech blog
HTML
1
star
36

xml-utils

XML utilities, mainly conversion between XML <=> array
PHP
1
star
37

go-throttled

Throttled HTTP Transport
Go
1
star
38

data-file

📁 File Manipulation in PHP
PHP
1
star
39

feed

Supply ordered feeds of articles.
PHP
1
star