Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pass an argument to pool function #89

Closed
BanterFace opened this issue Oct 12, 2019 · 1 comment
Closed

Can't pass an argument to pool function #89

BanterFace opened this issue Oct 12, 2019 · 1 comment

Comments

@BanterFace
Copy link

BanterFace commented Oct 12, 2019

Hi there. PHP 7.4.0RC1, CentOS 7.6.1810. Setup using composer.
Trying to execute this code:

<?php
require_once('/root/vendor/autoload.php');
use Spatie\Async\Pool;
$pool = Pool::create();

$collect = 'COLLECT';
for ($i=0; $i < 3; $i++) { 
	$pool -> add(function() use($collect){
		$collect .= "\n" . 1;
	}) -> catch(function($exception){
		echo($exception . "\n");
	});
}
$pool->wait();

echo($collect);

Got 3 warnings like that:

Spatie\Async\Output\ParallelError: PHP Warning: include(): Opis\Closure\ClosureStream::stream_set_option is not implemented! in /root/vendor/opis/closure/src/SerializableClosure.php on line 257
in /root/vendor/spatie/async/src/Output/ParallelError.php:11
Stack trace:
#0 /root/vendor/spatie/async/src/Process/ParallelProcess.php(126): Spatie\Async\Output\ParallelError::fromException()
#1 /root/vendor/spatie/async/src/Process/ProcessCallbacks.php(54): Spatie\Async\Process\ParallelProcess->resolveErrorOutput()
#2 /root/vendor/spatie/async/src/Process/ProcessCallbacks.php(38): Spatie\Async\Process\ParallelProcess->triggerError()
#3 /root/vendor/spatie/async/src/Pool.php(182): Spatie\Async\Process\ParallelProcess->triggerSuccess()
#4 /root/vendor/spatie/async/src/Pool.php(295): Spatie\Async\Pool->markAsFinished()
#5 /root/vendor/spatie/async/src/Pool.php(131): Spatie\Async\Pool->Spatie\Async{closure}()
#6 /home/tor-fake/web/hydraruma6mcunvp.onion/public_html/test.php(14): Spatie\Async\Pool->wait()
#7 {main}

...but, most importantly, the function does not work at all, at the end php echoes just 'COLLECT', while it should be different as you may see.
Can anyone please say what exactly I do wrong?

@brendt
Copy link
Contributor

brendt commented Oct 14, 2019

You would have to use a reference to $collect if you want to change it:

use(&$collect){

As to the error: it looks like your PHP installation is missing some stream-related functionality? If you want to get to the source of the problem, I recommend debugging in the opis package: https://github.com/opis/closure/blob/master/src/SerializableClosure.php

@brendt brendt closed this as completed Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants