承接 bluepsyduck/symfony-process-manager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bluepsyduck/symfony-process-manager

最新稳定版本:1.3.3

Composer 安装命令:

composer require bluepsyduck/symfony-process-manager

包简介

A process manager for Symfony processes, able to run them in parallel.

README 文档

README

GitHub release (latest SemVer) GitHub build Codecov

This package provides a simple process manager class to be able to execute multiple processes with a specified limit of parallel processes. The class expects the processes to use the Symfony Process component.

Usage

The usage of the process manager is straight forward and best explained with an example.

<?php
use BluePsyduck\SymfonyProcessManager\ProcessManager;
use Symfony\Component\Process\Process;

$numberOfParallelProcesses = 4; // The number of processes to execute in parallel.
$pollInterval = 100; // The interval to use for polling the processes, in milliseconds.
$processStartDelay = 0; // The time to delay the start of processes to space them out, in milliseconds.

$processManager = new ProcessManager($numberOfParallelProcesses, $pollInterval, $processStartDelay);

// Add some processes
// Processes get executed automatically once they are added to the manager. 
// If the limit of parallel processes is reached, they are placed in a queue and wait for a process to finish.
$processManager->addProcess(Process::fromShellCommandline('ls -l'));
$processManager->addProcess(Process::fromShellCommandline('ls -l'));

// Wait for all processes to finish
$processManager->waitForAllProcesses();

Callbacks

The process manager allows for some callbacks to be specified, which get called depending on the state of a process.

  • processStartCallback: Triggered before a process is started.
  • processFinishCallback: Triggered when a process has finished.
  • processTimeoutCallback: Triggered when a process timed out. Note that the processFinishCallback will be triggered afterwards as well.
  • processCheckCallback: Triggered whenever a process is checked for completion. Note that this callback is called periodically, but at least once, between the processStartCallback and the processFinishCallback or processTimeoutCallback respectively.

Each callback gets the process instance which triggered the event passed as only parameter. Here is an example of setting a processStartCallback:

<?php
use BluePsyduck\SymfonyProcessManager\ProcessManager;
use Symfony\Component\Process\Process;

$processManager = new ProcessManager();

$processManager->setProcessStartCallback(function (Process $process): void {
    echo 'Starting process: ' . $process->getCommandLine();
});

$processManager->addProcess(Process::fromShellCommandline('ls -l'));
$processManager->waitForAllProcesses();

统计信息

  • 总下载量: 759.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2018-09-06