PHP code example of uginroot / async-symfony-process
1. Go to this page and download the library: Download uginroot/async-symfony-process 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/ */
uginroot / async-symfony-process example snippets
use Symfony\Component\Process\Process;
use Uginroot\AsyncSymfonyProcess\Pool;
$queue = range(1, 10);
$processFactory = static function() use (&$queue):?Process{
if(count($queue) === 0){
return null;
}
$value = array_shift($queue);
return Process::fromShellCommandline(sprintf('echo %d', $value));
};
$pool = new Pool();
$pool->setProcessFactory($processFactory);
$pool->execute();
use Symfony\Component\Process\Process;
use Uginroot\AsyncSymfonyProcess\Pool;
use Uginroot\AsyncSymfonyProcess\ProcessWrapper;
$queue = range(1, 10);
$results = [];
$processFactory = static function() use (&$queue):?Process{
if(count($queue) === 0){
return null;
}
$value = array_shift($queue);
return Process::fromShellCommandline(sprintf('echo %d', $value));
};
$callback = static function(ProcessWrapper $processWrapper) use (&$results):void{
$results[] = (int)$processWrapper->getOutput();
};
$pool = new Pool();
$pool->setProcessFactory($processFactory);
$pool->setCallback($callback);
$pool->execute();