Created
October 24, 2016 09:04
-
-
Save necromant2005/744c9d5f552eb81efb33782459817853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use React\EventLoop\Factory as EventLoopFactory; | |
use WyriHaximus\React\ChildProcess\Pool\Pool\Fixed as FixedPool; | |
use WyriHaximus\React\ChildProcess\Pool\ProcessCollection\ArrayList as ProcessCollectionArrayList; | |
use React\ChildProcess\Process; | |
$tasks = []; | |
for ($i=0; $i<10; $i++) { | |
$id = ($i+1); | |
$wait = rand(3, 7); | |
//$wait = rand(5, 25); | |
$tasks[] = 'php child.php ' . $id . ' ' . $wait; | |
} | |
$loop = EventLoopFactory::create(); | |
var_dump($tasks); | |
$processCollection = new ProcessCollectionArrayList(array_map(function($task) use ($loop) { | |
return function() use ($loop, $task) { | |
$process = new React\ChildProcess\Process($task); | |
$promise = \WyriHaximus\React\childProcessPromise($loop, $process); | |
// $promise->then(function ($result) { | |
// var_export($result); | |
// }); | |
return $promise; | |
}; | |
}, $tasks)); | |
$pool = new FixedPool($processCollection, $loop, ['size' => 2]); | |
$loop->run(); | |
var_dump('ZZZ'); | |
//var_dump($processCollection); | |
//var_dump($pool); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment