PHP code example of nusje2000 / process-runner

1. Go to this page and download the library: Download nusje2000/process-runner library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nusje2000 / process-runner example snippets


use Nusje2000\ProcessRunner\Task;
use Nusje2000\ProcessRunner\TaskList;
use Symfony\Component\Process\Process;

$list = new TaskList([
    new Task('task name', new Process(['some-command'])),
    new Task('task name', new Process(['some-other-command'])),
]);

use Nusje2000\ProcessRunner\Factory\TaskListFactory;

$list = TaskListFactory::createFromArray([
    'task name' => 'command argument --option'
]);

use Nusje2000\ProcessRunner\Executor\ParallelExecutor;
use Nusje2000\ProcessRunner\TaskList;

$executor = new ParallelExecutor();
$executor->execute(new TaskList([]));

use Nusje2000\ProcessRunner\Executor\SequentialExecutor;
use Nusje2000\ProcessRunner\TaskList;

$executor = new SequentialExecutor();
$executor->execute(new TaskList([]));

use Nusje2000\ProcessRunner\Executor\ExecutorInterface;
use Nusje2000\ProcessRunner\Listener\CallbackListener;
use Nusje2000\ProcessRunner\TaskList;

$listener = new CallbackListener(static function (TaskList $taskList) {
    echo sprintf('There are %d running tasks.', $taskList->getRunningTasks()->count());
});

/** @var ExecutorInterface $executor */
$executor->addListener($listener);

use Nusje2000\ProcessRunner\Executor\ExecutorInterface;
use Nusje2000\ProcessRunner\Listener\ExecutionListener;
use Nusje2000\ProcessRunner\TaskList;

class RunningTaskListener implements ExecutionListener
{
    public function onTick(TaskList $taskList) : void
    {
        echo sprintf('There are %d running tasks.', $taskList->getRunningTasks()->count());
    }

    public function getPriority() : int{
        return 0;
    }
}

/** @var ExecutorInterface $executor */
$executor->addListener(new RunningTaskListener());

use Nusje2000\ProcessRunner\Executor\ExecutorInterface;
use Nusje2000\ProcessRunner\Listener\ConsoleListener;
use Symfony\Component\Console\Output\ConsoleOutput;

/** @var ExecutorInterface $executor */
$executor->addListener(new ConsoleListener(new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, true)));

use Nusje2000\ProcessRunner\Executor\ExecutorInterface;
use Nusje2000\ProcessRunner\Listener\StaticConsoleListener;
use Symfony\Component\Console\Output\ConsoleOutput;

/** @var ExecutorInterface $executor */
$executor->addListener(new StaticConsoleListener(new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, true)));