Bug 1.2.2 doesn't finish
PHP 8.2.18 (cli)
Sorry for not giving more details, but my knowledge about threads is too low.
Version 1.2.2 never reach die('done');
use Spatie\Fork\Fork;
$results = Fork::new()
->run(
function () {
return 'result from task 1';
},
function () {
return 'result from task 2';
},
function () {
return 'result from task 3';
},
);
die('done');
The bug is not present in 1.2.1
https://github.com/spatie/fork/compare/1.2.1...1.2.2
Maybe is needed $this->exit() and also exit()?
Works fine for me with 1.2.2. On PHP 8.3.6 but that shouldn't really matter.
I think a timeout / max execution time per fork should be preferable too, to timeout to the main thread again if something is hanging in the forked process. This can be done through a signal (alarm)
Probably better to use the more fleshed-out spatie/async if you need additional features like timeouts.
Thanks for that one, will probably implement it in my framework. I have json #parallel property to execute in parallel and with timeout its way more production ready instead of 30 sec
1.2.2 is also broken for me on latest PHP 8.3. Never returns.
https://github.com/spatie/fork/blob/1.2.2/src/Fork.php#L132
This line terminates the entire web request. Any reason it's not $this->exit()?
https://github.com/spatie/fork/compare/1.2.1..1.2.2
Correct me if I'm wrong, but I believe that particular exit() terminates the worker (from within the worker process) after it's finished executing its task. $this->exit() is a function of and for the parent process.
You're referring to a "web request". Be aware that Fork only works in a CLI context.
I think @redburn might be right about the problem here.
I can't reproduce this problem in a CLI command. When you try the code example in a web request it does not work, however when you revert back to 1.2.1 it does reach the die statement. However the results are not reliable as its not an intended usecase: just refreshing the page gives me different results each time.
Ah, disregard my issue then. 😅