parallel: How to launch multiple blocking processes

Terribly sorry for making an issue, but I’ve been stuck for a while.

I’m in the need to launch multiple blocking php scripts in a concurrent fashion. Its the same script 20 x times.

I’ve looked at https://github.com/amphp/parallel/blob/master/examples/process.php

and its child:

https://github.com/amphp/parallel/blob/master/examples/blocking-process.php

But I’m struggling to make it launch 20 children ( with different data )

I’ve got something like this:

$promises = [];
for($x = 0; $x <= 10; $x++)
{
	$process = new Process(__DIR__ . "/amp-runner.php");
	$process->start();
	$promises[] = $process->send(x);
}
$all_replies = Promise\wait(Promise\all($promises));
var_dump($all_replies);

But I can’t get it to work.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 68 (27 by maintainers)

Commits related to this issue

Most upvoted comments

@iNilo check this out: https://github.com/JanMikes/php-async-playground i think it is exactly what you are looking for 😃

Not at the moment, no, will try something later.

function runProcess($value) {
    return call(
        function () {
			$process = new Process(__DIR__ . "/amp-runner.php");
			yield $process->start();
			yield $process->send($x);
        }
    )
}

Loop::run(
    function () {
        $promises = [];
        for($x = 0; $x <= 10; $x++)
        {
            $promises[] = runProcess($x);
        }
        yield $promises;
    }
);

Ok. Tomorrow. I need to sleep now.