wizaplace / process
launch multi process concurrency
1.0.0
2019-02-06 07:26 UTC
Requires
- php: ^7.1.3
- symfony/process: ^4.2
Requires (Dev)
- phpstan/phpstan: ^0.11.1
- phpunit/phpunit: ^7
- squizlabs/php_codesniffer: *
This package is auto-updated.
Last update: 2024-11-12 09:04:08 UTC
README
Installation
composer require wizaplace/process
Usage
use Wizaplace\Process\AsyncProcess;
use Wizaplace\Process\MultiProcess;
use Wizaplace\Process\ProcessEvent;
use Symfony\Component\Process\Process;
$successCallback = function (Process $process, $startTime, $finishTime) {
echo $process->getOutput();
};
$processEventSuccess = new ProcessEvent(ProcessEvent::EVENT_SUCCESS, $successCallback);
$process1 = new AsyncProcess(new Process(['ls', '/tmp']));
$process1->addProcessEvent($processEventSuccess);
$process2 = new AsyncProcess(new Process(['ls', '/home']));
$process2->addProcessEvent($processEventSuccess);
$multiProcess = new MultiProcess();
$multiProcess
->addAsyncProcess($process1)
->addAsyncProcess($process2)
;
$multiProcess->run();
Using Event
event list:
- process start
- process failed
- process finish successful
use Wizaplace\Process\AsyncProcess;
use Wizaplace\Process\MultiProcess;
use Wizaplace\Process\ProcessEvent;
use Symfony\Component\Process\Process;
$successCallback = function (Process $process, $startTime, $finishTime) {
echo $process->getOutput();
};
$failedCallback = function (Process $process, $startTime, $finishTime) {
echo $process->getErrorOutput();
};
$processEventSuccess = new ProcessEvent(ProcessEvent::EVENT_SUCCESS, $successCallback);
$processEventFailed = new ProcessEvent(ProcessEvent::EVENT_FAILED, $failedCallback);
$process1 = new AsyncProcess(new Process(['ls', '/t11mp']));
$process1
->addProcessEvent($processEventSuccess)
->addProcessEvent($processEventFailed)
;
$process2 = new AsyncProcess(new Process(['ls', '/home']));
$process2
->addProcessEvent($processEventSuccess)
->addProcessEvent($processEventFailed)
;
$multiProcess = new MultiProcess();
$multiProcess
->addAsyncProcess($process1)
->addAsyncProcess($process2)
;
$multiProcess->run();