1

i use the Parallel PHP library, but i don't know how to pass variable of my script to a parallel thread. I view in the documentation that i must pass a array argument in the "run" function but i don't know how to access to the argument value.

My script :

<?php
$runtime = new \parallel\Runtime();


$future1 = $runtime->run(function(){

echo argv

},array(22,'hi')); // here the argv but how to access in this in $future1 ?
?>

The documentation link about parallel run function : https://www.php.net/manual/en/parallel-runtime.run.php

Thanks.

Errorj404
  • 43
  • 8

1 Answers1

0

I solved my problem. I fell on it really by a stroke of luck. Here is the solution : it was also enough to specify in the closure in the same order as the array the name associated with the values of the array. For example, here is an example:

<?php
$runtime = new \parallel\Runtime();

$myvar = 'hello';
$var2 = 'Guys';
$future1 = $runtime->run(function($first,$second){

echo $first.PHP_EOL; // hello
echo $second; //Guys

},array($myvar,$var2));

/*Result: 
hello
Guys
*/
?>
Errorj404
  • 43
  • 8