1. Go to this page and download the library: Download justmisha/php-multirunner 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/ */
justmisha / php-multirunner example snippets
use \JustMisha\MultiRunner\ScriptMultiRunner;
$maxParallelProcesses = 512; // determined by the machine on which it is runs
try {
$runner = ScriptMultiRunner($maxParallelProcesses, "/full/path/to/script");
} catch (RuntimeException $e) {
// handle an exception
}
for($i = 1; $i <= 1000000; $i++) {
$changingArg1 = $i - 1;
$changingArg2 = $i + 1;
$runner->addProcess((string)$i, $changingArg, $changingArg2);
}
$timeout = 15; // Timeout in seconds, depending on the machine it is running on.
try {
$results = $runner->runAndWaitForResults($timeout);
} catch (RuntimeException $e) {
// handle an exception
}
foreach ($results as $processId => $processResult) {
if $processResult->exitCode !== 0 {
echo "There were errors in " . $processId . ": " . $processResult->stderr;
continue;
}
$result = $processResult->stdout;
// handle a success result, whatever it is
};