vuongxuongminh / laravel-async

Package provide simple way to run code asynchronously for your Laravel application.
MIT License
154 stars 26 forks source link

AsyncFacade::run function issue #35

Open carlosMartin0213 opened 1 year ago

carlosMartin0213 commented 1 year ago

I read your ReadMe and installed laravel-async to my current project. All things are worked well, but only one problem is occured. It is running synchronously.

use VXM\Async\AsyncFacade as Async;
for ($i = 1; $i < 20; $i++) {
    Async::run(function () use ($i) {
        sleep(1);
        return $i;
    });
}
var_dump(implode(', ', Async::wait()));

And run following command to add config file, and asyn.php like your code is added to config directory. php artisan vendor:publish --provider="VXM\Async\AsyncServiceProvider" --tag="config"

After running this code, I can get result like this. "string(65) "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19" Is there anything I need to configure my project to run asynchronously? Thanks.

kirkbushell commented 1 year ago

@carlosMartin0213 as per the underlying library: https://github.com/spatie/async

You're probably missing the posix and pcntl extensions required in PHP to make it work. With that library, it falls back to synchronous by default.