似乎问题出在 shell 配置中,因为该命令ps被重写为仅显示子进程。
解决方案是要求您的托管服务提供商(或在允许的情况下自行更改)设置此变量:
SHELL="/bin/bash"
这个简单的修复使我能够使该功能正常工作。
现在我的Kernel.php样子如下:
$command = "ps faux | grep queue:work";
exec($command, $task_list);
// Process are duplicate in ps and show also the command as two single lines
$running_process = (count($task_list) / 2) - 1;
if($running_process < 1)
$schedule->command('queue:work --queue=high,low --tries=3')
->everyMinute();
else if($running_process > 5)
// If too many are active, restart everything to avoid overload
$schedule->call(function(){
Artisan::call('queue:restart');
})->everyMinute();
此代码确保至少有一个工作人员始终在运行,同时restart如果您有超过 5 个工作人员处于活动状态,则强制执行。