spatie / async

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

How to echo from the child process? #207

Closed santossoares closed 1 year ago

santossoares commented 1 year ago

I have a code that i need to echo from the child process. Is it possible to make the echo print on the console?

<?php

require_once "vendor/autoload.php";

use Spatie\Async\Pool;

$pool = Pool::create();

$pool->add(function () { for ($i = 0; $i < 5; $i++) { echo $i; sleep(1); } return 'end'; })->then(function ($output) { echo "Status $output" . PHP_EOL; });

$pool->wait();

benhdev commented 1 year ago

I also have a use case for this.

kirkbushell commented 1 year ago

You can't - you need to use Laravel's logger. The output doesn't get captured, but the result is.