PHP code example of justmisha / php-multirunner

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
        
    };

    public function someMethodInSomeClass(MultiRunnerInterface $runner) {
        ...
        $processId = 0;
        foreach ($params as $param) {
            $processId++;
            $runner->addProcess((string)$processId, $param);
        }
        $timeToWait = 60;
        
        try {
            $results = $runner->runAndWaitForResults($timeToWait);
        } catch (RuntimeException $e) {
            ...
        }               
        ...
    }
.ini
unit.exclude-python-node.xml

composer 

git clone https://github.com/JustMisha/php-multirunner.git your-folder-for-php-multirunner-code

composer install
test-linux-php-7.4.cmd