PHP code example of fichtme / symfony-command-runner

1. Go to this page and download the library: Download fichtme/symfony-command-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/ */

    

fichtme / symfony-command-runner example snippets




declare(strict_types=1);

use Fichtme\CommandRunner\CommandRunner;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\Process;

/** @var SymfonyStyle $io */
$runner = (new CommandRunner([
    new Process(['app:import', '--quiet']),
    new Process(['app:reindex', '--quiet']),
    new Process(['app:notify', '--env=prod']),
]))
    ->continueOnError(true)
    ->setIO($io)
    ->setLimit(3);

$runner->run();

foreach ($runner->getErrors() as $error) {
    // $error contains the executed command line and its error output.
}

$runner
    ->setBinary(PHP_BINARY)
    ->setSubPath(__DIR__ . '/bin/console')
    ->run();

$lock = CommandRunner::lock('app:import', 'tenant-42');

try {
    // Run the protected work.
} finally {
    $lock->release();
}