Skip to content

Commit 68f754e

Browse files
committed
Updates PHP / Symfony / dependencies and add documentation
1 parent d96474b commit 68f754e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+334
-121
lines changed

.github/workflows/build-docker-image-ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ name: Build Docker image ci
33
on:
44
workflow_dispatch: ~
55

6+
permissions:
7+
contents: read
8+
packages: write
9+
610
jobs:
711
build:
812
name: Build Docker image ci
913
runs-on: ubuntu-latest
1014
steps:
11-
- uses: actions/checkout@v2
12-
- run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login --username steevanb --password-stdin
15+
- uses: actions/checkout@v5
16+
17+
-
18+
name: Log in to GitHub Container Registry
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
1325
- run: bin/ci/docker --push

.github/workflows/build-docker-image-release.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ name: Build Docker image release
33
on:
44
workflow_dispatch: ~
55

6+
permissions:
7+
contents: read
8+
packages: write
9+
610
jobs:
711
build:
8-
name: Build Docker image release
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v2
12-
- run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login --username steevanb --password-stdin
13-
- run: bin/release/docker --push
12+
name: Build Docker image ci
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v5
16+
17+
-
18+
name: Log in to GitHub Container Registry
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- run: bin/release/docker --push

.github/workflows/ci.yml

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,19 @@
11
name: CI
2-
on: [push]
3-
jobs:
4-
phpcs:
5-
runs-on: ubuntu-latest
6-
steps:
7-
- uses: actions/checkout@v2
8-
- run: bin/ci/phpcs
9-
10-
phpstan:
11-
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
php: [--php=8.2, --php=8.3]
15-
symfony: [--symfony=7.0, --symfony=7.1]
16-
steps:
17-
- uses: actions/checkout@v2
18-
- uses: ./.github/actions/ci-env
19-
- run: bin/ci/phpstan ${{ matrix.php }} ${{ matrix.symfony }}
20-
21-
phpdd:
22-
runs-on: ubuntu-latest
23-
steps:
24-
- uses: actions/checkout@v2
25-
- uses: ./.github/actions/ci-env
26-
- run: bin/ci/phpdd
272

28-
composer-normalize:
29-
runs-on: ubuntu-latest
30-
steps:
31-
- uses: actions/checkout@v2
32-
- run: bin/ci/composer-normalize
3+
on: [push]
334

34-
composer-require-checker:
5+
jobs:
6+
validate:
357
runs-on: ubuntu-latest
368
steps:
37-
- uses: actions/checkout@v2
38-
- uses: ./.github/actions/ci-env
39-
- run: bin/ci/composer-require-checker
9+
- uses: actions/checkout@v5
4010

41-
composer-validate:
42-
runs-on: ubuntu-latest
43-
steps:
44-
- uses: actions/checkout@v2
45-
- run: bin/ci/composer-validate
11+
- name: Cache vendor
12+
uses: actions/cache@v4
13+
with:
14+
path: vendor
15+
key: composer-${{ hashFiles('composer.json') }}
4616

47-
shellcheck:
48-
runs-on: ubuntu-latest
49-
steps:
50-
- uses: actions/checkout@v2
51-
- run: bin/ci/shellcheck
17+
- run: bin/ci/env
5218

53-
unused-scanner:
54-
runs-on: ubuntu-latest
55-
steps:
56-
- uses: actions/checkout@v2
57-
- run: bin/ci/unused-scanner
58-
59-
phpunit:
60-
runs-on: ubuntu-latest
61-
strategy:
62-
matrix:
63-
php: [--php=8.2, --php=8.3]
64-
symfony: [--symfony=7.0, --symfony=7.1]
65-
steps:
66-
- uses: actions/checkout@v2
67-
- uses: ./.github/actions/ci-env
68-
- run: bin/ci/phpunit ${{ matrix.php }} ${{ matrix.symfony }}
19+
- run: bin/ci/validate -v --theme=summary

README.md

Lines changed: 137 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,148 @@
77

88
# php-parallel-processes
99

10-
Work in progress ;)
10+
Execute processes in parallel.
11+
12+
Examples of use: start your environment, CI tools...
1113

1214
# Installation
1315

16+
## Use official Docker image
17+
18+
You can use the official Docker image to not install anything:
19+
[steevanb/php-parallel-processes:x.y.z](https://hub.docker.com/r/steevanb/php-parallel-processes/tags).
20+
21+
Example:
22+
```bash
23+
docker \
24+
run \
25+
--rm \
26+
--tty \
27+
--interactive \
28+
--volume "$(pwd)":"$(pwd)" \
29+
--workdir "$(pwd)" \
30+
steevanb/php-parallel-processes:x.y.z \
31+
php parallel-processes.php
32+
```
33+
34+
### If your processes use docker
35+
36+
If processes in `parallel-processes.php` use Docker, you have to add a volume on your Docker socket:
37+
```bash
38+
--volume /var/run/docker.sock:/var/run/docker.sock
1439
```
40+
41+
All official `php-parallel-processes` images have Docker and Docker compose installed, so you only need to add a volume on the socket.
42+
43+
### alpine, bookworm and buster
44+
45+
3 Docker images are provided for each `php-parallel-processes` version, use the one you want depending on your needs:
46+
* `alpine`: smaller version, but could be "too much simple" sometimes
47+
* `buster`: middle version, contains almost everything needed
48+
* `bookworm`: larger version, should contain what you need
49+
50+
## Install as Composer dependency
51+
52+
If you want to add `php-parallel-processes` directly in your project:
53+
54+
```bash
1555
composer require steevanb/php-parallel-processes ^1.0
1656
```
1757

18-
# Usage with Docker
58+
# Create processes configuration
1959

20-
If you don't want to install it as dependency, you can use the official Docker image:
21-
[steevanb/php-parallel-processes:x.y.z](https://hub.docker.com/r/steevanb/php-parallel-processes/tags).
60+
You need to create a configuration for your processes, written in PHP.
61+
62+
Example: [bin/start.php](bin/start.php)
63+
64+
## Basic example
65+
66+
```php
67+
<?php
68+
69+
declare(strict_types=1);
70+
71+
use Steevanb\ParallelProcess\{
72+
Console\Application\ParallelProcessesApplication,
73+
Process\Process
74+
};
75+
use Symfony\Component\Console\Input\ArgvInput;
76+
77+
# If you use the official Docker image, you should use the Composer global autoload
78+
require $_ENV['COMPOSER_GLOBAL_AUTOLOAD_FILE_NAME'];
79+
# If you use the Composer dependency version, you should use your Composer autoload
80+
require __DIR__ . '/vendor/autoload.php';
81+
82+
(new ParallelProcessesApplication())
83+
->addProcess((new Process(['first', 'process']))->setName('First process'))
84+
->addProcess((new Process(['second', 'process']))->setName('Second process'))
85+
->run(new ArgvInput($argv));
86+
```
87+
88+
## Configurations
89+
90+
### Global timeout
91+
92+
93+
You can configure the global timeout with `ParallelProcessesApplication::setTimeout()`.
94+
95+
Default value: `null` (no timeout).
96+
97+
```php
98+
(new ParallelProcessesApplication())
99+
// Timeout is in seconds, here we will have a 10s timeout
100+
->setTimeout(10)
101+
```
102+
103+
### Refresh interval
104+
105+
You can configure the refresh interval, to scan all processes status and start the next ones,
106+
with `ParallelProcessesApplication::setRefreshInterval()`.
107+
108+
Default value: `10000` (10ms)
109+
110+
```php
111+
(new ParallelProcessesApplication())
112+
// Timeout is in microseconds, here we will have a 500ms timeout
113+
->setRefreshInterval(50000)
114+
```
115+
116+
### Maximum processes in parallel
117+
118+
You can configure the maximum number of processes in parallel
119+
with `ParallelProcessesApplication::setMaximumParallelProcesses()`.
120+
121+
Default value: `null` (no maximum)
122+
123+
```php
124+
(new ParallelProcessesApplication())
125+
// Here we will have maximum 3 processes in parallel
126+
->setMaximumParallelProcesses(3)
127+
```
128+
129+
### Theme
130+
131+
`php-parallel-processes` comes with 2 themes:
132+
* [default](src/Console/Application/Theme/DefaultTheme.php)
133+
* Output everything
134+
* Use verbosity (`-v`, `-vv` or `-vvv`) to add execution time and process outputs
135+
* Should be used when you need to see live processes status, most of the time ;)
136+
* [summary](src/Console/Application/Theme/SummaryTheme.php)
137+
* Output only the start and the end of parallel processes
138+
* Use verbosity (`-v`, `-vv` or `-vvv`) to add execution time and process outputs
139+
* Should be used when you don't need to see live processes status, in CI for example
140+
141+
Configure it with `ParallelProcessesApplication::setTheme()`:
142+
```php
143+
use Steevanb\ParallelProcess\Console\Application\Theme\DefaultTheme();
144+
145+
(new ParallelProcessesApplication())
146+
->setTheme(new DefaultTheme())
147+
```
148+
149+
You can also configure it in CLI with `--theme` (CLI override PHP configuration):
150+
```bash
151+
php parallel-processes.php --theme summary
152+
```
153+
154+
You can create your own theme by implementing [ThemeInterface](src/Console/Application/Theme/ThemeInterface.php).

bin/DependenciesVersions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __construct(array $argv)
3434
->phpVersions
3535
->add('8.2')
3636
->add('8.3')
37+
->add('8.4')
3738
->setReadOnly();
3839
}
3940

@@ -42,6 +43,8 @@ public function __construct(array $argv)
4243
->symfonyVersions
4344
->add('7.0')
4445
->add('7.1')
46+
->add('7.2')
47+
->add('7.3')
4548
->setReadOnly();
4649
}
4750
}

bin/ci/composer-require-checker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ readonly ROOT_DIR="$(realpath "$(dirname "$(realpath "$0")")/../..")"
66

77
source "${ROOT_DIR}"/bin/ci/dockerise.inc.bash
88

9-
composer-require-checker --ansi "${@}"
9+
composer-require-checker --ansi $@

bin/ci/phpcs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ phpcs \
1919
--report=steevanb\\PhpCodeSniffs\\Reports\\Steevanb \
2020
--cache="${ROOT_DIR}"/var/ci/phpcs/cache \
2121
. \
22-
"${@}"
22+
$@

bin/ci/phpdd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ readonly ROOT_DIR="$(realpath "$(dirname "$(realpath "$0")")/../..")"
66

77
source "${ROOT_DIR}"/bin/ci/dockerise.inc.bash
88

9-
phpdd --exclude=vendor,var "${@}" .
9+
phpdd --exclude=vendor,var $@ .

bin/ci/phpstan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ phpVersion=
1010
symfonyVersion=
1111
phpstanParameters=
1212
clearCache=false
13-
for arg in "${@}"; do
13+
for arg in "$@"; do
1414
if [ "${arg:0:6}" == "--php=" ]; then
1515
phpVersion="${arg:6}"
1616
elif [ "${arg:0:10}" == "--symfony=" ]; then

bin/ci/phpstan.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ function createPhpstanProcess(string $phpVersion, string $symfonyVersion): Proce
3636

3737
(new ParallelProcessesApplication())
3838
->addProcesses(createPhpstanProcesses($dependenciesVersions))
39+
->setRefreshInterval(50000)
3940
->run(new ArgvInput($dependenciesVersions->getFilteredArgv()->toArray()));

0 commit comments

Comments
 (0)