您可以使用该命令,但它只能在您注销或重新启动后才能使用
nohup php artisan queue:work --daemon &
尾随的和号 (&) 导致进程在后台启动,因此您可以继续使用 shell 而不必等到脚本完成。
见nohup
nohup - 运行不受挂断影响的命令,输出到非 tty
这会将信息输出到您运行命令的目录中名为 nohup.out 的文件中。如果您对输出不感兴趣,您可以将 stdout 和 stderr 重定向到 /dev/null,或者类似地您可以将其输出到您的普通 laravel 日志中。例如
nohup php artisan queue:work --daemon > /dev/null 2>&1 &
nohup php artisan queue:work --daemon > app/storage/logs/laravel.log &
但您还应该使用Supervisord 之类的东西来确保服务保持运行并在崩溃/失败后重新启动。
运行队列:用 supervisord 监听
supervisord 是一个 *nix 实用程序,用于监视和控制以下进程,它是 /etc/supervisord.conf 的一部分,运行良好。
用于 queue:listen 的 supervisord.conf 部分
[program:l5beauty-queue-listen]
command=php /PATH/TO/l5beauty/artisan queue:listen
user=NONROOT-USER
process_name=%(program_name)s_%(process_num)d
directory=/PATH/TO/l5beauty
stdout_logfile=/PATH/TO/l5beauty/storage/logs/supervisord.log
redirect_stderr=true
numprocs=1
您需要替换 /PATH/TO/ 以匹配您的本地安装。同样,用户设置对于您的安装也是唯一的。