vdlp/oc-horizon-plugin
Composer 安装命令:
composer require vdlp/oc-horizon-plugin
包简介
Laravel Horizon integration for October CMS
README 文档
README
Provides a seamless integration of Laravel Horizon 5.0 inside October CMS.
Queues, With X-Ray Vision. Supercharge your queues with a beautiful dashboard and code-driven configuration.
A match made in heaven
Horizon is developed by the core developers of the Laravel framework and provides a robust queue monitoring solution for Laravel's Redis queue. Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures.
Open Source
Horizon is 100% open source, so you're free to dig through the source to see exactly how it works. See something that needs to be improved? Just send us a pull request on GitHub.
Requirements
- October CMS 3.0 or 4.0
- PHP 8.0.2 or higher
- PHP extensions:
ext-pcntl,ext-posixandext-redis. - Supervisor, see Laravel 9.x supervisor configuration.
Installation
composer require vdlp/oc-horizon-plugin
Turn off auto discovery for laravel/horizon (important)
Because this plugin has it's own HorizonServiceProvider which extends from the Laravel\Horizon\HorizonServiceProvider
we need to prevent the Laravel\Horizon\HorizonServiceProvider from being loaded due to Laravels' auto package discovery.
You should add the dont-discover option to your projects composer.json file (which is located in the root path of your project).
"extra": {
"laravel": {
"dont-discover": [
"laravel/horizon"
]
}
}
IMPORTANT: After adding these lines, make sure you execute
composer updateto apply the changes. You also need to remove the filestorage/framework/packages.phpfile. No worries. This file will be re-generated once you access your project.
IMPORTANT: Make sure the
composer.jsonis deployed to your hosting site. This will be parsed by te framework to determine which service providers should be ignored.
Configuration
php artisan horizon:install
- Configure Laravel Horizon settings file at
config/horizon.php, please make sureusecontainshorizon(see the configuration snippet below).
/*
|--------------------------------------------------------------------------
| 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' => 'horizon',
- Add connection to
config/queue.php:
'redis' => [
'driver' => 'redis',
'connection' => 'horizon', // References: databases.redis.horizon
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => env('QUEUE_RETRY_AFTER', 90),
'block_for' => null,
],
- Add Redis database configuration for Horizon specifically to
config/databases.php:
'redis' => [
'cluster' => false,
'client' => 'phpredis',
'default' => [
// ..
],
'horizon' => [
'host' => env('HORIZON_REDIS_HOST', '127.0.0.1'),
'password' => env('HORIZON_REDIS_PASSWORD'),
'port' => env('HORIZON_REDIS_PORT', 6379),
'database' => env('HORIZON_REDIS_DATABASE', '1'),
]
],
- Modify the queue connection
QUEUE_CONNECTION(which can be found inconfig/queue.php) toredisas such:
/*
|--------------------------------------------------------------------------
| Default Queue Driver
|--------------------------------------------------------------------------
|
| The Laravel queue API supports a variety of back-ends via an unified
| API, giving you convenient access to each back-end using the same
| syntax for each one. Here you may set the default queue driver.
|
| Supported: "null", "sync", "database", "beanstalkd",
| "sqs", "iron", "redis"
|
*/
'default' => env('QUEUE_CONNECTION', 'redis'),
.envshould at least have the followingQUEUE_andHORIZON_variables:
#
# Queue
#
QUEUE_CONNECTION = "redis"
QUEUE_RETRY_AFTER = 90
#
# Horizon
#
HORIZON_PREFIX = "myproject-local:"
HORIZON_REDIS_HOST = "127.0.0.1"
HORIZON_REDIS_PASSWORD = null
HORIZON_REDIS_PORT = 6379
HORIZON_REDIS_DATABASE = "1"
It's recommended to add your Queue Worker Configuration config.horizon.environments to the .env file as well.
Server configuration
- Add the following to the
supervisordconfiguration on the server. The completesupervisordconfiguration can be found on the supervisor website. - See Configuring Supervisor (Official Laravel Documentation).
[program:<queue-name>-queue]
process_name=%(program_name)s_%(process_num)02d
directory=/<myproject-directory>
command=/<path-to-php>/php /<myproject-directory>/artisan horizon
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=<user>
numprocs=1
redirect_stderr=true
stdout_logfile=/var/log/supervisord/<queue-name>-queue.log
stopwaitsecs=90
- Add the following to the cronjob configuration on the server. This will make sure the Horizon metrics are created periodically.
* * * * * /<path-to-php>/php /<myproject-directory>/artisan schedule:run > /dev/null
Creating Job classes
Follow the instructions at Laravel 9.x generating job classes on how to make Job classes.
Please note that the use of the
php artisan make:jobcommand is not supported in October CMS. October CMS is using a different application structure in comparison to a generic Laravel project.
This plugin also contains an example job file: Vdlp\Horizon\Example.
This example file does not use the SerializesModels and InteractsWithQueue trait.
Testing
- Log-in to the backend.
- Put application in debug mode using the
.envfile:APP_DEBUG=trueor by changing thedebugkey in theconfig/app.phpfile. - Run Horizon using this command:
php artisan horizon. - Now run this command to push some
Vdlp\Horizon\Examplejobs to the queue:
php artisan vdlp:horizon:push-example-jobs
- Check the Horizon dashboard at
/backend/vdlp/horizon/dashboardor at/horizon. - Each
Vdlp\Horizon\Examplejob should log a random string to the application log (level =debug).
Documentation
Please go to the Laravel website for detailed documentation about Laravel Horizon.
Questions
If you have any question about how to use this plugin, please don't hesitate to contact us at octobercms@vdlp.nl. We're happy to help you. You can also visit the support forum and drop your questions/issues there.
vdlp/oc-horizon-plugin 适用场景与选型建议
vdlp/oc-horizon-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40.71k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2021 年 06 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「october」 「octobercms」 「horizon」 「laravel-queues」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vdlp/oc-horizon-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vdlp/oc-horizon-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vdlp/oc-horizon-plugin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Horizon Restart for Laravel.
User plugin for October CMS
This is my package LaravelHorizonMonitor
Maintenance page plugin
Location plugin for October CMS
Adds a command to easily clear all your defined queues at once.
统计信息
- 总下载量: 40.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-only
- 更新时间: 2021-06-22