定制 documateai/watchtower 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

documateai/watchtower

Composer 安装命令:

composer require documateai/watchtower

包简介

Cross-platform Laravel queue monitoring and worker management

README 文档

README

Latest Version on Packagist PHP Version License

Cross-platform Laravel queue monitoring and worker management dashboard

Watchtower provides queue monitoring and worker management capabilities similar to Laravel Horizon, but with full cross-platform support including Windows. Unlike Horizon, which relies on PCNTL signals (Unix-only), Watchtower uses a polling-based approach for worker control that works on Windows, Linux, and macOS.

Features

  • 📊 Queue Monitoring Dashboard - Real-time job tracking, status monitoring, and metrics
  • ⚙️ Worker Management - Start, stop, pause, resume workers from the web UI
  • 🖥️ Cross-Platform - Works on Windows, Linux, and macOS
  • 📋 Job Tracking - Job status, payload, exceptions, retries, worker info
  • 🎨 Modern UI - Alpine.js dark-themed dashboard (no build step required)
  • 🗑️ Automatic Cleanup - Time-based pruning of old job records

Requirements

  • PHP 8.2+
  • Laravel 11 or 12
  • Redis (optional -- required only when using the default redis command bus driver)

Installation

composer require documateai/watchtower

Publish the configuration and assets:

php artisan vendor:publish --tag=watchtower-config
php artisan vendor:publish --tag=watchtower-migrations
php artisan migrate

Configuration

The package configuration is published to config/watchtower.php:

return [
    // Dashboard URL path
    'path' => env('WATCHTOWER_PATH', 'watchtower'),

    // Route middleware
    'middleware' => ['web'],

    // Authorization gate
    'gate' => env('WATCHTOWER_GATE', 'viewWatchtower'),

    // Command bus driver: 'redis' or 'database'
    'command_bus' => env('WATCHTOWER_COMMAND_BUS', 'redis'),

    // Job retention (days)
    'retention' => [
        'completed' => 7,
        'failed' => 30,
    ],

    // Supervisor configuration
    'supervisors' => [
        'default' => [
            'connection' => 'redis',
            'queue' => '*',           // Auto-discover all queues!
            // Or specify explicit queues:
            // 'queue' => ['default', 'emails', 'notifications'],
            'min_processes' => 1,
            'max_processes' => 10,
            'tries' => 3,
            'timeout' => 60,
        ],
    ],
];

Usage

Starting the Supervisor

Run the supervisor to automatically manage your queue workers:

php artisan watchtower:supervisor

The supervisor will:

  • Auto-discover all queues in your application (Redis keys, job records)
  • Maintain the minimum number of workers
  • Restart failed workers automatically
  • Monitor worker health via heartbeats

Tip: Set 'queue' => '*' in your config (default) to automatically detect and process all queues. Or specify explicit queues: 'queue' => ['default', 'emails', 'high']

Manual Worker Control

Start a single worker manually:

php artisan watchtower:worker default

Zero-Downtime Deployments

Gracefully restart all workers after deploying new code:

php artisan watchtower:restart

Options:

  • --queue=emails - Only restart workers on a specific queue
  • --force - Force immediate restart (don't wait for current job)

Workers will finish processing their current job, then restart with fresh code.

Terminating All Processes

Stop the supervisor and all workers (similar to horizon:terminate):

php artisan watchtower:terminate

Options:

  • --wait - Wait for all workers to finish before returning

Accessing the Dashboard

Visit /watchtower in your browser. By default, the dashboard is only accessible in local environments. Configure the gate in your AuthServiceProvider for production:

Gate::define('viewWatchtower', function ($user) {
    return in_array($user->email, [
        'admin@example.com',
    ]);
});

Pruning Old Jobs

Watchtower automatically prunes old job records. You can also run the prune command manually:

php artisan watchtower:prune

How It Works

Polling-Based Control via CommandBus

Unlike Horizon which uses PCNTL signals (Unix-only), Watchtower uses a CommandBusInterface for worker control with two drivers:

  • Redis (default) -- fast, uses Redis::connection()
  • Database -- no Redis required, uses watchtower_commands table
WATCHTOWER_COMMAND_BUS=database  # set in .env to use database driver
  1. Dashboard sends command via CommandBus: $commandBus->put("watchtower:worker:{id}:command", "stop")
  2. Worker polls the CommandBus every 3 seconds
  3. Worker reads and executes the command
  4. Worker confirms status in database

This approach provides:

  • ✅ Cross-platform compatibility
  • ✅ No PCNTL dependency
  • ✅ Redis optional (database driver available)
  • ✅ Simple debugging
  • ⚠️ 1-3 second response delay (acceptable for worker management)

Dashboard Updates

The dashboard polls for updates every 3 seconds (configurable). This provides near-real-time visibility into:

  • Job counts and status
  • Worker health and activity
  • Throughput metrics

Artisan Commands

Command Description
watchtower:supervisor Start the supervisor to manage workers
watchtower:worker {queue} Start a single worker process
watchtower:restart Gracefully restart all workers
watchtower:terminate Stop supervisor and all workers
watchtower:status Show current supervisor and worker status
watchtower:prune Prune old job records

License

MIT License. See LICENSE.md for details.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Security

If you discover a security vulnerability, please send an email instead of using the issue tracker. See SECURITY.md for details.

Credits

documateai/watchtower 适用场景与选型建议

documateai/watchtower 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 205 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「queue」 「monitoring」 「windows」 「laravel」 「workers」 「cross-platform」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 documateai/watchtower 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 documateai/watchtower 我们能提供哪些服务?
定制开发 / 二次开发

基于 documateai/watchtower 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 205
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-05