Laravel队列及supervisor

队列

  • 参考文档
laravel学院:[http://laravelacademy.org/post/8993.html](http://laravelacademy.org/post/8993.html) laravelChina:[https://laravel-china.org/docs/laravel/5.5/queues/1324](https://laravel-china.org/docs/laravel/5.5/queues/1324) 使用Laravel Queue不得不明白的知识:[https://laravel-china.org/articles/3729/use-laravel-queue-to-understand-the-knowledge](https://laravel-china.org/articles/3729/use-laravel-queue-to-understand-the-knowledge)

  • 使用
创建类: php artisan make:job SendSmsJob

  • 创建失败数据库
php artisan queue:failed-table php artisan migrate

Laravel队列及supervisor
文章图片
failed-jobs.sql
  • queue.php配置

    Laravel队列及supervisor
    文章图片
Laravel队列及supervisor
文章图片
  • SendSmsJob类

    Laravel队列及supervisor
    文章图片
  • 调用

    Laravel队列及supervisor
    文章图片
  • 测试

    Laravel队列及supervisor
    文章图片

    php artisan queue:listen --queue=register
Laravel队列及supervisor
文章图片
queue执行之后, redis中list消失, 数据库中短信日志出现发送成功记录

Laravel队列及supervisor
文章图片

Laravel队列及supervisor
文章图片

Supervisor laravel学院文档中有介绍
  • 安装
    yum install supervisor
  • 配置
    新建/etc/supervisord.d/mchregister.ini, 内容如下
[program:mch-register] process_name=%(program_name)s_%(process_num)02d command=/usr/local/php/bin/php /data/wwwroot/haojikeji/platform/mch/artisan queue:work--quiet --queue=register --delay=3 --sleep=3 autostart=true autorestart=true user=root numprocs=8 redirect_stderr=true[program:mch-project] process_name=%(program_name)s_%(process_num)02d command=/usr/local/php/bin/php /data/wwwroot/haojikeji/platform/mch/artisan queue:work--quiet --queue=project --delay=3 --sleep=3 autostart=true autorestart=true user=root numprocs=8 redirect_stderr=true[program:mch-settled] process_name=%(program_name)s_%(process_num)02d command=/usr/local/php/bin/php /data/wwwroot/haojikeji/platform/mch/artisan queue:work--quiet --queue=project_settled --delay=3 --sleep=3 autostart=true autorestart=true user=root numprocs=8 redirect_stderr=true

  • 启动
supervisorctl reread supervisorctl update supervisorctl start mch-register:* supervisorctl start mch-project:* supervisorctl start mch-settled:*

  • 【Laravel队列及supervisor】报错

    Laravel队列及supervisor
    文章图片
启动服务 systemctl start supervisord 再继续执行 supervisorctl reread

    推荐阅读