spatie / async

Easily run code asynchronously
https://spatie.be/en/opensource/php
MIT License
2.65k stars 179 forks source link

[Debian 10 / PHP-8.0.17] Spatie\Async\Output\ParallelError #186

Closed brmcghee closed 2 years ago

brmcghee commented 2 years ago

Hello,

we have been trying to test this and it works on windows but when we use debian we get this error:

[POOL:SUPPORTED]1[/POOL:SUPPORTED]

[ERROR] Spatie\Async\Output\ParallelError in /src/vendor/spatie/async/src/Output/ParallelError.php:11

Stack trace: 0 /src/vendor/spatie/async/src/Process/ParallelProcess.php(125): Spatie\Async\Output\ParallelError::fromException() 1 /src/vendor/spatie/async/src/Process/ProcessCallbacks.php(54): Spatie\Async\Process\ParallelProcess->resolveErrorOutput() 2 /src/vendor/spatie/async/src/Pool.php(232): Spatie\Async\Process\ParallelProcess->triggerError() 3 /src/vendor/spatie/async/src/Pool.php(328): Spatie\Async\Pool->markAsFailed() 4 /src/vendor/symfony/process/Process.php(887): Spatie\Async\Pool->Spatie\Async{closure}() 5 /src/vendor/symfony/process/Process.php(213): Symfony\Component\Process\Process->stop() 6 [internal function]: Symfony\Component\Process\Process->__destruct() 7 {main} [/ERROR]

class TaskScheduler:

function __construct()
{
    $this->pool = Pool::create()->sleepTime(500)->concurrency(10);

}

function add(Task $task)
{
    $this->pool->add($task)
        ->catch(function (\Throwable $error)
        {
            echo '[POOL:SUPPORTED]'.Pool::isSupported().'[/POOL:SUPPORTED]'.PHP_EOL;
            echo '[ERROR]'.PHP_EOL.$error.PHP_EOL.'[/ERROR]'.PHP_EOL;

        });
    return $this;
}

public function run()
{
    $this->pool->wait();
}

class CreateTask extended Task

public function configure()
{
}

public function run()
{
    echo 'i worked';
}

When our script starts it calls the following:

entryfile:

$taskManager = new TaskScheduler;
$taskManager ->add(new CreateTask);

So i have run the composer tests and all passed. I have verified pcntl and posix are enabled.

above Script works on a Windows 11 Environment with PHP v 8.0.8. Throws above noted error with PHP 7.4 or 8.0 on Debian 10.

command running: php -f entryfile.php

The Goal is that the entry point will create individual pools for each group of tasks that we add to it. Each Pool will then process everything it needs to based on the tasks added to it.

php -v

PHP 8.0.17 (cli) (built: Mar 18 2022 11:55:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.17, Copyright (c), by Zend Technologies

thanks in advance.

brmcghee commented 2 years ago

I also want to note,

with "entrypoint" we have also done it this way: $taskManager->add(new CreateTask)->run();

This works on windows 10 with php 8.0.17

But on Debian Php 8.0.17 it returns an error on the code:

TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, no array or string given

0 {main} in /vendor/spatie/async/src/Output/SerializableException.php:29
Stack trace:
0 /vendor/spatie/async/src/Process/ParallelProcess.php(121): Spatie\Async\Output\SerializableException->asThrowable()
1 /vendor/spatie/async/src/Process/ProcessCallbacks.php(54): Spatie\Async\Process\ParallelProcess->resolveErrorOutput()
2 /vendor/spatie/async/src/Pool.php(232): Spatie\Async\Process\ParallelProcess->triggerError()
3 /vendor/spatie/async/src/Pool.php(328): Spatie\Async\Pool->markAsFailed()
4 /vendor/spatie/async/src/Pool.php(154): Spatie\Async\Pool->Spatie\Async\{closure}()
5 /class/scheduler.class.php(53): Spatie\Async\Pool->wait()
6 entrypoint.php(15): TaskScheduler->run()
7 {main}
spatie-bot commented 2 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

SoftwareZimbabwe commented 1 year ago

For me it was running without specifying the binary (am running in a docker container). By default, it was using the php-fpm as the binary, which seems not to exists / work. So when creating the pull, specify the PATH of php which you can get by running whereis php form within the docker container:

$pool = Pool::create()->withBinary('/usr/local/bin/php');