如何使Laravel Queue系统在服务器上运行 [英] How to keep Laravel Queue system running on server
问题描述
我最近设置了Laravel Queue系统.基本内容是cronjob,该命令调用将作业添加到队列的命令,并调用第二个发送电子邮件的命令.
当我SSH进入服务器并运行php artisan queue:listen时,系统正常工作,但是如果我关闭终端,则监听器将关闭,并且作业会堆积并排在队列中,直到我ssh重新进入并再次运行监听. /p>
使队列系统在后台运行而不需要通过ssh保持连接打开的最佳方法是什么?
我尝试运行php artisan queue:work --daemon
,它完成了队列中的作业,但是当我关闭终端时,它关闭了连接和后台进程.
正在运行
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 之类的东西,以确保该服务保持运行并在崩溃/失败后重新启动.
I recently setup a Laravel Queue system. The basics are a cronjob calls a command which adds jobs to a queue and calls a second command which sends an email.
The system works when I ssh into my server and run php artisan queue:listen, but if I close my terminal the listener shuts down and the jobs stack up and sit in queue until I ssh back in and run listen again.
What is the best way to keep my queue system running in the background without needing to keep my connection open via ssh?
I tried running php artisan queue:work --daemon
, and it completed the jobs in the queue, but when I closed my terminal it closed the connection and the background process.
Running
nohup php artisan queue:work --daemon &
Will prevent the command exiting when you log out.
The trailing ampersand (&) causes process start in the background, so you can continue to use the shell and do not have to wait until the script is finished.
See nohup
nohup - run a command immune to hangups, with output to a non-tty
This will output information to a file entitled nohup.out in the directory where you run the command. If you have no interest in the output you can redirect stdout and stderr to /dev/null, or similarly you could output it into your normal laravel log. For example
nohup php artisan queue:work --daemon > /dev/null 2>&1 &
nohup php artisan queue:work --daemon > app/storage/logs/laravel.log &
But you should also use something like Supervisord to ensure that the service remains running and is restarted after crashes/failures.
这篇关于如何使Laravel Queue系统在服务器上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!