spatie / async

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

Async does not work in Phar #232

Open Arcesilas opened 1 month ago

Arcesilas commented 1 month ago

Hi, I've been struggling to have async work in a Phar before I realize the child process is executed as a command like php /path/to/project/vendor/spatie/async/src/Runtime/ChildRuntime.php ... which cannot work when it's encapsulated in a Phar.

Since it's not possible to directly run a script located in a Phar from CLI, is there any plan on supporting Phar in a future?

It would require the ParentRuntime to call the main script with specific arguments and the Phar stub to handle these arguments to not run the main "parent script", but ChildRuntime.

Not sure it's possible to use async in a Phar without modifying how ParentRuntime runs the ChildRuntime.

Arcesilas commented 1 month ago

Me again,

I've just tested to change ParentRuntime::childProcessScript to $GLOBALS['argv'][0] : https://github.com/spatie/async/blob/c270e692f6eabafb4312e1ecd44e062032785635/src/Runtime/ParentRuntime.php#L45

Here I use $GLOBALS only for testing purposes.

My main script handles the CLI arguments:

if ($argc > 1) {
    require dirname(__DIR__) . '/vendor/spatie/async/src/Runtime/ChildRuntime.php';
}

This is very basic because this script does not take any argument, but you have the idea.

And it works.

So I think it should be nice to be able to simply customize the script we want to call as ChildRuntime somewhere in our main script.