spatie / async

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

PHP Warning: Failed to set memory limit to 0 bytes (Current memory usage is 2097152 bytes) in Unknown on line 0 #226

Closed Naghal closed 1 month ago

Naghal commented 5 months ago

Using the code from the documentation, I get the warning PHP Warning: Failed to set memory limit to 0 bytes (Current memory usage is 2097152 bytes) in Unknown on line 0.

Code

$pool = Pool::create();
foreach (range(1, 5) as $i) {
    $pool[] = async(function () use ($i) {
        // Something to execute in a child process.

    })->then(function (int $output) {
        // Handle output returned from the child process.

    })->catch(function ( $exception) {
        dd($exception);
        // Handle exceptions thrown in the child process.
    });
}

$r = await($pool);

Stacktrace

Spatie\Async\Output\ParallelError {#1428 // app/Collections/CustomerCommentCollection.php:25
  #message: "PHP Warning:  Failed to set memory limit to 0 bytes (Current memory usage is 2097152 bytes) in Unknown on line 0
"
  #code: 0
  #file: "
/var/www/html/vendor
/spatie/async/
src/Output/ParallelError.php"
  #line: 11
  trace: {

/var/www/html/vendor
/spatie/async/
src/Output/ParallelError.php:11 {

Spatie\Async\Output
\
ParallelError::fromException($exception): self …
      › {
      ›     return new self($exception);
      › }
    }

/var/www/html/vendor
/spatie/async/
src/Process/ParallelProcess.php:125 {

Spatie\Async\Process
\
ParallelProcess->resolveErrorOutput(): Throwable …
      › if (! $exception instanceof Throwable) {
      ›     $exception = ParallelError::fromException($exception);
      › }
    }

/var/www/html/vendor
/spatie/async/
src/Process/ProcessCallbacks.php:54 {

Spatie\Async\Process
\
ParallelProcess->triggerError() …
      › {
      ›     $exception = $this->resolveErrorOutput();
      › 
    }

/var/www/html/vendor
/spatie/async/
src/Process/ProcessCallbacks.php:38 {

Spatie\Async\Process
\
ParallelProcess->triggerSuccess() …
      › if ($this->getErrorOutput()) {
      ›     $this->triggerError();
      › 
    }

/var/www/html/vendor
/spatie/async/
src/Pool.php:223 {

Spatie\Async
\
Pool->markAsFinished(Runnable $process) …
      › 
      › $this->results[] = $process->triggerSuccess();
      › 
    }

/var/www/html/vendor
/spatie/async/
src/Pool.php:358 {

Spatie\Async
\
Pool->handleFinishedProcess(int $pid, int $status) …
      › if ($status === 0) {
      ›     $this->markAsFinished($process);
      › 
    }

/var/www/html/vendor
/spatie/async/
src/Pool.php:344 {

Spatie\Async\Pool->Spatie\Async
\
{closure} …
      › 
      ›     $this->handleFinishedProcess($pid, $status['status']);
      › }
    }

/var/www/html/vendor
/spatie/async/
src/Pool.php:168 {

Spatie\Async
\
Pool->wait(?callable $intermediateCallback = null): array …
      › {
      ›     while ($this->inProgress) {
      ›         foreach ($this->inProgress as $process) {
    }

/var/www/html/vendor
/spatie/async/
src/helpers.php:22 {
      await(Pool $pool): array …
      › {
      ›     return $pool->wait();
      › }
    }

/var/www/html
/
app/Collections/CustomerCommentCollection.php:30 {

App\Collections
\
CustomerCommentCollection->attachTextComment() …
      › 
      › $r = await($pool);
      › dd($r);
    }

I have also tried this snippet

use Spatie\Async\Pool;

$pool = Pool::create();

foreach ($things as $thing) {
    $pool->add(function () use ($thing) {
        // Do a thing
    })->then(function ($output) {
        // Handle success
    })->catch(function (Throwable $exception) {
        // Handle exception
    });
}

$pool->wait();

It gives the error sh: 1: exec: : Permission denied.

Im using php 8.3 and the posix and pcntl extensions are both enabled.

$pool->isSupported() returns true.

What could be the issue?

spatie-bot commented 1 month 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.