fn.php
declare(strict_types=1);
namespace Name\Space;
// use function func_get_args;
use function function_exists;
index.php
use parallel\Runtime;
\error_reporting(\E_ALL);
class Flow
{
protected(set) Runtime $runtime;
protected array $futures = [];
function __construct()
{
$this->runtime = new Runtime;
}
function exec(\Closure $callback): self
{
$wrapTask = static function (\Closure $task) {
try {
var_dump('task exit');
exit;
// $task();
} catch (\Throwable $e) {
\print_r([
$e->getMessage(),
$e->getFile(),
$e->getLine(),
]);
}
};
\var_dump('runtime run task');
$this->futures[] = $this->runtime->run($wrapTask, [$callback]);
return $this;
}
}
$flow = new Flow();
$flow->runtime->run(static function () {
try {
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/fn.php';
} catch (\Throwable $e) {
\print_r([
$e->getMessage(),
$e->getFile(),
$e->getLine(),
]);
}
// print_r(\get_included_files());
var_dump('boot');
});
$flow->exec(static function () {
var_dump('t1');
});
$flow->exec(static function () {
var_dump('t2');
});
$flow->exec(static function () {
var_dump('t3');
});
exit(PHP_EOL . 'main flow end' . PHP_EOL);
In the output, we see that only one task is running
string(16) "runtime run task"
string(16) "runtime run task"
string(16) "runtime run task"
main flow end
string(4) "boot"
string(9) "task exit"
If you comment out the inclusion of one file from autoload.php or fn.php, you will get the following result
string(16) "runtime run task"
string(16) "runtime run task"
string(16) "runtime run task"
main flow end
string(4) "boot"
string(9) "task exit"
string(9) "task exit"
string(9) "task exit"
I think the general problem is clear, the tasks don't start under unclear conditions.
When I reproduced it, there was a lot of chaos. I commented out one line, and it worked, but when I commented out another line, it didn't work. I spent hours playing with the code in the fn.php file to find a pattern, but I couldn't.
Another important point is that the autoload.php file also affects this. If I comment it out, all the tasks will run, but I'm not sure about that. I want to share this observation with you. It all started with a problem in issue #374. I'll keep you updated...
Env:
PHP 8.4.9 (cli) (built: Jul 1 2025 15:27:25) (ZTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Zend Engine v4.4.9, Copyright (c) Zend Technologies
parallel version => 1.2.11
opcache - off
Windows 10 Pro
fn.php
index.php
In the output, we see that only one task is running
If you comment out the inclusion of one file from autoload.php or fn.php, you will get the following result
I think the general problem is clear, the tasks don't start under unclear conditions.
When I reproduced it, there was a lot of chaos. I commented out one line, and it worked, but when I commented out another line, it didn't work. I spent hours playing with the code in the fn.php file to find a pattern, but I couldn't.
Another important point is that the autoload.php file also affects this. If I comment it out, all the tasks will run, but I'm not sure about that. I want to share this observation with you. It all started with a problem in issue #374. I'll keep you updated...
Env: