steevanb/php-parallel-processes
最新稳定版本:1.2.0
Composer 安装命令:
composer require steevanb/php-parallel-processes
包简介
Call processes in parallel
README 文档
README
php-parallel-processes
Execute processes in parallel.
Examples of use: start your environment, CI tools...
Installation
Use official Docker image
You can use the official Docker image to not install anything: steevanb/php-parallel-processes:x.y.z.
Example:
docker \
run \
--rm \
--tty \
--interactive \
--volume "$(pwd)":"$(pwd)" \
--workdir "$(pwd)" \
steevanb/php-parallel-processes:x.y.z \
php parallel-processes.php
If your processes use docker
If processes in parallel-processes.php use Docker, you have to add a volume on your Docker socket:
--volume /var/run/docker.sock:/var/run/docker.sock
All official php-parallel-processes images have Docker and Docker compose installed, so you only need to add a volume on the socket.
alpine, bookworm and buster
3 Docker images are provided for each php-parallel-processes version, use the one you want depending on your needs:
alpine: smaller version, but could be "too much simple" sometimesbuster: middle version, contains almost everything neededbookworm: larger version, should contain what you need
Install as Composer dependency
If you want to add php-parallel-processes directly in your project:
composer require steevanb/php-parallel-processes ^1.2
Create processes configuration
You need to create a configuration for your processes, written in PHP.
Example: bin/start.php
Basic example
<?php declare(strict_types=1); use Steevanb\ParallelProcess\{ Console\Application\ParallelProcessesApplication, Process\Process }; use Symfony\Component\Console\Input\ArgvInput; # If you use the official Docker image, you should use the Composer global autoload require $_ENV['COMPOSER_GLOBAL_AUTOLOAD_FILE_NAME']; # If you use the Composer dependency version, you should use your Composer autoload require __DIR__ . '/vendor/autoload.php'; (new ParallelProcessesApplication()) ->addProcess((new Process(['first', 'process']))->setName('First process')) ->addProcess((new Process(['second', 'process']))->setName('Second process')) ->run(new ArgvInput($argv));
Configurations
Global timeout
You can configure the global timeout with ParallelProcessesApplication::setTimeout().
Default value: null (no timeout).
(new ParallelProcessesApplication()) // Timeout is in seconds, here we will have a 10s timeout ->setTimeout(10)
Refresh interval
You can configure the refresh interval, to scan all processes status and start the next ones,
with ParallelProcessesApplication::setRefreshInterval().
Default value: 10000 (10ms)
(new ParallelProcessesApplication()) // Timeout is in microseconds, here we will have a 500ms timeout ->setRefreshInterval(50000)
Maximum processes in parallel
You can configure the maximum number of processes in parallel
with ParallelProcessesApplication::setMaximumParallelProcesses().
Default value: null (no maximum)
(new ParallelProcessesApplication()) // Here we will have maximum 3 processes in parallel ->setMaximumParallelProcesses(3)
Theme
php-parallel-processes comes with 2 themes:
- default
- Output everything
- Use verbosity (
-v,-vvor-vvv) to add execution time and process outputs - Should be used when you need to see live processes status, most of the time ;)
- summary
- Output only the start and the end of parallel processes
- Use verbosity (
-v,-vvor-vvv) to add execution time and process outputs - Should be used when you don't need to see live processes status, in CI for example
Configure it with ParallelProcessesApplication::setTheme():
use Steevanb\ParallelProcess\Console\Application\Theme\DefaultTheme(); (new ParallelProcessesApplication()) ->setTheme(new DefaultTheme())
You can also configure it in CLI with --theme (CLI override PHP configuration):
php parallel-processes.php --theme summary
You can create your own theme by implementing ThemeInterface.
统计信息
- 总下载量: 3.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2021-08-24