我的需求是:
我想启动5个子进程干活,子进程异常退出时,想让主进程重新拉起这个子进程。
现在测试下来。每轮重新拉起都会少进程,至到剩下最后1个进程。
是我的问题,还是swoole的问题?
php7.3
swoole 4.6.5
<?php
use Swoole\Process\Manager;
use Swoole\Process\Pool;
$pname_tpl='php-Test:%s:%d';
$pname =sprintf($pname_tpl, 'master', -1);
swoole_set_process_name($pname);
echo $pname."\tstart done\n";
$pm = new Manager();
$pm->addBatch(5, function (Pool $pool, int $workerId) use($pname_tpl){
$pname = sprintf($pname_tpl, 'km', $workerId);
try {
swoole_set_process_name($pname);
echo $pname."\t\tstart done\n";
$i=3;
while ($i--){
sleep(1);
}
}
catch (\Throwable $e){
echo printf('%s process restart: %d %s', $pname, $e->getLine(), $e->getMessage());
}
echo $pname."\t\t exit\n";
sleep(3);
});
$pm->start();
测试正常