randika-srimal/queue-manager
Composer 安装命令:
composer require randika-srimal/queue-manager
包简介
A Laravel package to manage multiple queue workers similar to Horizon, with memory monitoring and graceful shutdown
README 文档
README
A Laravel package to manage multiple queue workers similar to Horizon, with memory monitoring and graceful shutdown capabilities. This package allows you to run multiple queue workers with different configurations from a single command.
Features
- 🚀 Multiple Worker Processes - Spawn multiple workers with different configurations
- 🧠 Memory Monitoring - Automatically restart workers that exceed memory limits
- 🔄 Auto-Restart - Workers are restarted when they crash or terminate
- 🛑 Graceful Shutdown - Properly handles SIGTERM, SIGINT (Ctrl+C), and SIGHUP signals
- ⚙️ Configurable - Easy configuration file for all worker settings
- 📊 Process Monitoring - Real-time display of worker status and PIDs
Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
- PCNTL extension (for signal handling)
Installation
Install the package via Composer:
composer require randika-srimal/queue-manager
For Local Development
If you're developing this package locally, add it to your Laravel project's composer.json:
{
"repositories": [
{
"type": "path",
"url": "./packages/queue-manager"
}
],
"require": {
"randika-srimal/queue-manager": "@dev"
}
}
Then run:
composer update randika-srimal/queue-manager
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=queue-manager-config
This will create config/queue-manager.php in your Laravel project. Edit this file to configure your workers:
<?php return [ 'workers' => [ [ 'connection' => 'database', 'queue' => 'default', 'processes' => 3, 'memory' => 128, // Maximum memory in MB before restart 'timeout' => 60, // Maximum execution time per job in seconds 'sleep' => 3, // Seconds to sleep when no jobs available 'tries' => 3, // Number of times to attempt a job ], [ 'connection' => 'redis', 'queue' => 'high-priority,default', 'processes' => 5, 'memory' => 256, 'timeout' => 60, 'sleep' => 1, 'tries' => 3, ], ], 'memory_check_interval' => 30, // How often to check memory (seconds) 'restart_delay' => 2, // Delay before restarting a worker (seconds) ];
Usage
Start the queue manager:
php artisan queue:manage
Options
--no-restart- Disable automatic restart of failed workers
php artisan queue:manage --no-restart
Stopping the Queue Manager
Press Ctrl+C to gracefully shutdown all workers. The manager will:
- Send SIGTERM to all worker processes
- Wait up to 10 seconds for workers to finish current jobs
- Force kill any remaining processes
How It Works
- Worker Spawning - The command reads the configuration and spawns the specified number of worker processes for each queue configuration
- Process Monitoring - Continuously monitors all worker processes
- Memory Checking - Periodically checks memory usage and restarts workers exceeding limits
- Auto-Restart - Automatically restarts workers that crash or terminate unexpectedly
- Signal Handling - Catches shutdown signals and gracefully terminates all child processes
Example Configuration
Database Queue with Email Workers
'workers' => [ [ 'connection' => 'database', 'queue' => 'default', 'processes' => 3, 'memory' => 128, 'timeout' => 60, 'sleep' => 3, 'tries' => 3, ], [ 'connection' => 'database', 'queue' => 'emails', 'processes' => 2, 'memory' => 128, 'timeout' => 120, 'sleep' => 5, 'tries' => 2, ], ],
Redis Queue with Priority
'workers' => [ [ 'connection' => 'redis', 'queue' => 'high-priority,default,low-priority', 'processes' => 5, 'memory' => 256, 'timeout' => 60, 'sleep' => 1, 'tries' => 3, ], ],
Process Supervisor
For production environments, it's recommended to run the queue manager under a process supervisor like systemd or Supervisor.
Systemd Example
Create /etc/systemd/system/queue-manager.service:
[Unit] Description=Laravel Queue Manager After=network.target [Service] Type=simple User=www-data WorkingDirectory=/var/www/html ExecStart=/usr/bin/php /var/www/html/artisan queue:manage Restart=always RestartSec=3 [Install] WantedBy=multi-user.target
Enable and start:
sudo systemctl enable queue-manager
sudo systemctl start queue-manager
Supervisor Example
Create /etc/supervisor/conf.d/queue-manager.conf:
[program:queue-manager] process_name=%(program_name)s command=php /var/www/html/artisan queue:manage autostart=true autorestart=true user=www-data redirect_stderr=true stdout_logfile=/var/www/html/storage/logs/queue-manager.log
Update and start:
sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start queue-manager
License
The MIT License (MIT). Please see License File for more information.
Credits
Inspired by Laravel Horizon's process management capabilities.
randika-srimal/queue-manager 适用场景与选型建议
randika-srimal/queue-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「laravel」 「worker」 「queue-manager」 「horizon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 randika-srimal/queue-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 randika-srimal/queue-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 randika-srimal/queue-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Queue
PHP AMQP Binding Library
SlimQ Enables You to push jobs to background workers
A Laravel package to monitor queue jobs.
A lightweight task queue on top of rybakit/phive-queue
A replica of the AWS Elastic Beanstalk worker SQS daemon (sqsd) in PHP
统计信息
- 总下载量: 77
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-07