异步群发邮件队列运行命令方法

1.在laravel项目目录运行

php artisan queue:work

2.启动队列监听服务

queue:work 命令有个缺陷,就是每次有新任务推送到队列后需要手动登录到服务器并运行该命令,任务才会被执行,这显然是不合理的,对此我们可以使用一些自动化解决方案。

2.1一种方式是将 artisan queue:listen 命令加入到服务器启动脚本中该命令会在新任务推送到队列时自动调用 artisan queue:work。这种方案的问题是 queue:listen 命令会一直挂在那里,消耗CPU资源,而且一旦命令挂掉,新的任务还是无法执行,更好的解决方案是使用 Supervisor 来运行 queue:listen。
1.启动队列监听服务
通过下面这条指令启动队列监听服务,它会自动处理队列任务:
php artisan queue:listen

在linux中,如果想让它在后台执行,可以这样:
nohup php artisan queue:listen &

在crontab -e中加入命令轮询处理
* * * * * php /home/wwwroot/fcgadmin/artisan queue:work

2.2 php artisan queue:listen 命令加入到服务器启动脚本

3.最优解Supervisor流程

yum install supervisor
安装好后在/etc/会生成一个supervisord.conf文件及一个supervisord.d文件目录
supervisord.conf是一些默认配置,可自行修改
vim /etc/supervisord.conf
[include]默认配置是制定.ini,因个人习惯命名为.conf文件,因此修改配置如下:

[include]
files = supervisord.d/*.conf

supervisord.d目录用来存放用户自定义的进程配置
cd /etc/supervisord.d
touch fcg.conf
编辑其内容

[program:fcg-queue-listen]
command=php /home/wwwroot/fcgadmin/artisan queue:listen
user=root
process_name=%(program_name)s_%(process_num)d
directory=/home/wwwroot/fcgadmin
stdout_logfile=/var/log/supervisor/supervisord.log
redirect_stderr=true
numprocs=1

4.查看进程listen

ps -ef |grep listen
kill pid 杀死进程

5.supervisorctl 是 supervisord的命令行客户端工具

0.supervisord -c /etc/supervisord.conf 启动supervisord服务
1.supervisorctl status:查看所有进程的状态
2.supervisorctl stop es:停止es
3.supervisorctl start es:启动es
4.supervisorctl restart es: 重启es
5.supervisorctl update :配置文件修改后可以使用该命令加载新的配置
6.supervisorctl reload: 重新启动配置中的所有程序

你可能感兴趣的:(异步群发邮件队列运行命令方法)