文档地址:https://learnku.com/docs/laravel/7.x/horizon/7514

安装
提示:由于 Horizon 使用了异步进程信号,所以 PHP 7.1+ 以上版本才可以使用。
           队列数据是存在Redis里的,所以要确保队列连接在 queue 配置文件的 redis 项已经正确设置。
我们使用 Composer 安装 Horizon 到 Laravel 项目:

composer require laravel/horizon

安装完成后,使用 Artisan 命令 vendor:publish 发布前端资源:

php artisan vendor:publish --provider="Laravel\Horizon\HorizonServiceProvider"

配置
分别是配置文件 config/horizon.php 和存放在 public/vendor/horizon 文件夹中的 CSS 、JS 等页面资源文件。
balance 配置项
Horizon 提供了三种负载均衡策略以供选择:simple、auto 和 false,simple 是默认策略,在进程之间平均分配进入任务:
'balance' => 'simple',
auto 策略基于队列当前负载调整每个队列的工作进程数量。例如,如果 notifications 队列有 1000 个等待执行的任务而 render 队列是空的,那么 Horizon 将会为 notifications 队列分配更多的工作进程直到队列为空。
如果把 balance 选项设置为 false,就会使用默认的 Laravel 行为,也就是按照配置文件中的排列顺序处理队列。

<?phpreturn [/*|--------------------------------------------------------------------------| Horizon Domain|--------------------------------------------------------------------------|| This is the subdomain where Horizon will be accessible from. If this| setting is null, Horizon will reside under the same domain as the| application. Otherwise, this value will serve as the subdomain.|*/'domain' => null,/*|--------------------------------------------------------------------------| Horizon Path|--------------------------------------------------------------------------|| This is the URI path where Horizon will be accessible from. Feel free| to change this path to anything you like. Note that the URI will not| affect the paths of its internal API that aren't exposed to users.|*/'path' => 'horizon',/*|--------------------------------------------------------------------------| Horizon Redis Connection|--------------------------------------------------------------------------|| This is the name of the Redis connection where Horizon will store the| meta information required for it to function. It includes the list| of supervisors, failed jobs, job metrics, and other information.|*/'use' => 'default',/*|--------------------------------------------------------------------------| Horizon Redis Prefix|--------------------------------------------------------------------------|| This prefix will be used when storing all Horizon data in Redis. You| may modify the prefix when you are running multiple installations| of Horizon on the same server so that they don't have problems.|*/'prefix' => env('HORIZON_PREFIX', 'horizon:'),/*|--------------------------------------------------------------------------| Horizon Route Middleware|--------------------------------------------------------------------------|| These middleware will get attached onto each Horizon route, giving you| the chance to add your own middleware to this list or change any of| the existing middleware. Or, you can simply stick with this list.|*/'middleware' => ['web'],/*|--------------------------------------------------------------------------| Queue Wait Time Thresholds|--------------------------------------------------------------------------|| This option allows you to configure when the LongWaitDetected event| will be fired. Every connection / queue combination may have its| own, unique threshold (in seconds) before this event is fired.|*/'waits' => ['redis:default'         => 600,'DtCubeTuyaDeviceData'  => 600,'DtCubeTuyaDeviceEvent' => 600,'DtCubeOrderAutoClose'  => 600,'DtCubeDeaultQueue'     => 600,'DtCubeAzureData'       => 600,'DtCubeAzureEvent'      => 600],/*|--------------------------------------------------------------------------| Job Trimming Times|--------------------------------------------------------------------------|| Here you can configure for how long (in minutes) you desire Horizon to| persist the recent and failed jobs. Typically, recent jobs are kept| for one hour while all failed jobs are stored for an entire week.|*/'trim' => ['recent'        => 60,'completed'     => 60,'recent_failed' => 10080,'failed'        => 10080,'monitored'     => 10080,],/*|--------------------------------------------------------------------------| Fast Termination|--------------------------------------------------------------------------|| When this option is enabled, Horizon's "terminate" command will not| wait on all of the workers to terminate unless the --wait option| is provided. Fast termination can shorten deployment delay by| allowing a new instance of Horizon to start while the last| instance will continue to terminate each of its workers.|*/'fast_termination' => false,/*|--------------------------------------------------------------------------| Memory Limit (MB)|--------------------------------------------------------------------------|| This value describes the maximum amount of memory the Horizon worker| may consume before it is terminated and restarted. You should set| this value according to the resources available to your server.|*/'memory_limit' => 64,/*|--------------------------------------------------------------------------| Queue Worker Configuration|--------------------------------------------------------------------------|| Here you may define the queue worker settings used by your application| in all environments. These supervisors and settings handle all your| queued jobs and will be provisioned by Horizon during deployment.|*/'environments' => ['production' => ['production-1'   => ['connection' => 'rabbitmq','queue'      => [],'balance'    => 'auto','processes'  => 50,'tries'      => 3,],],'local' => ['local-1'   => ['connection' => 'rabbitmq','queue'      => ['test1','test2',],'balance'    => 'auto','minProcesses'  => 1,'minProcesses'  => 10,'tries'      => 3,],'local-2'   => ['connection' => 'rabbitmq','queue'      => ['test6','test7',],'balance'    => 'auto','minProcesses'  => 1,'minProcesses'  => 10,'tries'      => 3,],],],
];
?>

至此安装配置完毕,浏览器打开 https://pi.fogbow.cn/horizon 访问控制台

运行 Horizon
如果你已经在配置文件 config/horizon.php 中配置过工作进程,就可以使用 Artisan 命令 horizon 来启动 Horizon,该命令会启动所有配置的工作进程:
Linux 命令后面加 & 表示设置此进程为后台进程

php artisan horizon

你可以使用 Artisan 命令 horizon:pause 和 horizon:continue 来暂停或继续处理队列任务:
php artisan horizon:pause
php artisan horizon:continue
你还可以使用 Artisan 命令 horizon:terminate 来优雅地终止 Horizon 主进程 —— Horizon 会在所有当前正在执行的任务全部完成后退出:
php artisan horizon:terminate

这个时候后可以把 php artisan queue:work省略

ok✌️

【相关链接】

(一)CentOS7安装RabbitMQ  https://blog.csdn.net/weixin_37689230/article/details/112276503
(二)laravel整合rabbitmq消息队列  https://blog.csdn.net/weixin_37689230/article/details/112321216
(三)Horizon 队列管理工具  https://blog.csdn.net/weixin_37689230/article/details/112366571
(四)RabbitMQ基础知识  https://blog.csdn.net/weixin_37689230/article/details/112542844

(三)Horizon 队列管理工具相关推荐

  1. Horizon 队列管理工具常用命令

    运行horizon php artisan horizon 后台运行horizon php artisan horizon & 暂停执行队列任务 php artisan horizon:pau ...

  2. 每个人的商学院--管理基础(第三章:管理工具)--读书笔记

    第三章:管理工具 面向业绩:梦想归梦想,绩效归绩效 读书笔记: 管理工作并非总能收获大团圆的结局,还要时常做出真正艰难的决定. 管理只对绩效负责. 绩效就是达成公司的经营目标. 公司里的两层关系:第一 ...

  3. 三款日志管理工具横向对比:Splunk vs Sumo Logic vs Logstash

    在生产环境记录应用的运行日志已经成为惯例,但日志需要经过处理和分析才有意义,第三方日志管理工具的出现正旨在解决这个问题.软件分析公司Takipi负责产品市场的Josh Dreyfuss今日撰文,比较了 ...

  4. Linux(三)远程登录管理工具

    远程登录管理工具,是为了不需要去到电脑面前操作 毕竟如果有上百台服务器,怎么可能一台一台的去操作. 所以有必要用一台电脑,连接上不同的服务器操作会更方便 要用远程登录,自然要先设置好网络 首先打开虚拟 ...

  5. 测试管理工具列表大全

    ID Name Notes 1 TestDirector/Quality Center 业界第一个基于Web的测试管理系统,它可以在您公司组织内进行全球范围内测试的协调.通过在一个整体的应用系统中提供 ...

  6. 信息系统项目管理师必背核心考点(五十七)知识管理工具

    科科过为您带来软考信息系统项目管理师核心重点考点(五十七)知识管理工具,内含思维导图+真题 [信息系统项目管理师核心考点]知识分类 一.显性知识 1.凡是能以文字与数字表达,随时都可以在个人之间相互传 ...

  7. Linux笔记 No.20---(进程管理工具:ps、pstree、top、pgrep、kill、killall、pkill、查看系统资源的使用vmstat)

    文章目录 一.定时任务crontab实现每秒执行 二.进程 (一)Linux程序与进程 1.程序和进程的区别 2.进程和线程的区别 3.父子进程的关系 三.进程管理工具 (一)ps命令 (二)pstr ...

  8. day9 进程 线程 threading multiprocessing 队列 主机批量管理工具

    一.进程与线程 1.进程 进程是系统资源加上一个或多个线程的集合 进程只能在一个时间干一件事,如果想同时干两件事或多件事,进程就无能为力了. 进程在执行的过程中如果阻塞,例如等待输入,整个进程就会挂起 ...

  9. docker学习(三) 安装docker的web可视化管理工具

    1.docker是一个一款很轻便的应用容器引擎,为了更好的管理和使用docker,使用web可视化管理工具似乎更符合大多数人的需求.在这里,我给大家分享下自己使用过的几款web工具:docker UI ...

最新文章

  1. 微信小程序 textarea 简易解决方案
  2. python统计个数的函数_Python
  3. 【转】ASP.NET验证控件详解(非空验证,比较验证,范围验证,正则表达式,自定义验证)...
  4. VMWare 黑苹果卡在Logo页面
  5. axure中的拐弯箭头_Axure 8.0制作水平方向上一直来回移动的箭头
  6. 使用XMANAGER 联接LINUX 后使用SQLPLUS 不能使用BACKSPACE 回格键.
  7. 代码chaid_[转载]经典决策树之SAS实现--CHAID
  8. iOS-AFNetworking参数和多文件同时上传【多文件上传】
  9. 【数据结构与算法】获取链表中值算法
  10. android百分比布局失效,Android 百分比布局库【原创】
  11. android web view
  12. PHP防止表单重复提交的解决方法
  13. notepad++弹出菜单
  14. 顺利通过PMP考试 PMP备考总结
  15. 扫雷游戏网页版_梦幻西游出网页版,王者出新英雄阿古朵,谁在杀死国产游戏的创新...
  16. 腾讯股票接口API(4)——计算分时线平均值
  17. 信号处理基础-matlab-wavread-audioread
  18. MPLS 网络技术 — 组网方案
  19. 2017秋季赛Web安全测试训练赛wp【安恒】
  20. yolov4离线安装笔记

热门文章

  1. 想自己上线微信小程序一定要会代码?
  2. mysql最高安全级别双一_MySQL技术体系之核心参数
  3. 学编程脚本 android,Auto.js安卓免root脚本开发教程
  4. 7-3 航空公司VIP客户查询 (25 分)C语言实现
  5. 5年后将有一半企业加码隐私计算,如何应对主权技术封锁?|算力隐私专栏
  6. 史上最全的sqlserver运维分析工具,汇总都在这里了,适合sqlserver的dba人员
  7. 【英语】VOA60-second science听力
  8. 机器学习笔记-投票法(Voting)理论与实现
  9. 数据结构 实验14(1-2班):(深入理解索引存储结构)三元组存储的稀疏矩阵建立行列索引并求鞍点
  10. IBM 上海 LBS offer入手总结