PHPackages                             vat/vatcron - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. vat/vatcron

ActiveLibrary[Framework](/categories/framework)

vat/vatcron
===========

A high-performance cron task plugin for Webman framework

014PHP

Since Jun 4Pushed 1mo agoCompare

[ Source](https://github.com/markowner/vatcron)[ Packagist](https://packagist.org/packages/vat/vatcron)[ RSS](/packages/vat-vatcron/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Vatcron - 高性能 Webman 定时任务插件
===========================

[](#vatcron---高性能-webman-定时任务插件)

 [ ![webman logo](https://camo.githubusercontent.com/c0b52a664b7b9b98063439bea4d211c54eaf3e2f089430fcb12e73401e8ed2cd/68747470733a2f2f7777772e776f726b65726d616e2e6e65742f696d672f6c6f676f2e706e67) ](https://github.com/walkor/webman)

Vatcron 是一款专为 [Webman](https://www.workerman.net/doc/webman/) 框架设计的高性能、企业级定时任务管理插件。它利用 Workerman 的多进程和协程能力，实现了秒级精度的任务调度、实时可视化的日志监控以及高可靠的分布式锁机制，非常适合处理高并发、高频次的后台任务。

🚀 核心特性
------

[](#-核心特性)

- **⏱ 秒级精度调度**：支持标准的 Crontab 表达式（6位），精确到秒级执行任务。
- **⚡️ 高性能架构**：
    - **多进程隔离**：调度器（Scheduler）、执行器（Executor）、日志服务（LogServer）独立进程，互不干扰。
    - **协程/异步支持**：底层支持 Swoole 协程，轻松应对高并发 I/O 密集型任务。
- **📊 实时监控**：基于 WebSocket 的实时日志推送，任务执行情况尽在掌握。
- **🔒 分布式锁**：内置 Redis 分布式锁，确保多实例部署时任务不重复执行。
- **🛡 健壮稳定**：
    - **平滑重启/停止**：完善的信号处理机制，确保任务执行中不丢失数据。
    - **自动重试**：支持任务失败自动重试配置。
- **🔌 丰富的任务类型**：
    - **Command**：执行系统命令
    - **Class**：调用 PHP 类方法
    - **URL**：发送 HTTP 请求
    - **Shell**：执行 Shell 脚本

📋 环境要求
------

[](#-环境要求)

- PHP &gt;= 8.1
- Webman &gt;= 1.5
- Workerman &gt;= 4.1 或 &gt;= 5.0
- Redis 扩展 (必选)
- Swoole 扩展 (推荐，用于协程模式)

📦 安装
----

[](#-安装)

### 1. Composer 安装

[](#1-composer-安装)

```
composer require vat/vatcron
```

### 2. 导入数据库

[](#2-导入数据库)

创建必要的数据库表（`vat_crontab` 和 `vat_crontab_log`）：

```
mysql -u root -p your_database  true,
    // 任务扫描间隔（秒）
    'scan_interval' => 5,
    // 定时任务表名
    'table_cron' => 'vat_crontab',
    // 定时任务日志表名
    'table_log' => 'vat_crontab_log',
    // 定时任务队列名称
    'cron_queue' => 'vatcron:cron_queue',
    // 定时任务日志队列名称
    'lock_prefix' => 'vatcron:lock:',
    // 定时任务日志订阅频道
    'log_subscribe' => 'vatcron:logs',
    // 是否将执行日志写入文件
    'log_write_file' => false,
];
```

💻 使用指南
------

[](#-使用指南)

### 1. 服务管理

[](#1-服务管理)

Vatcron 提供了一套标准的命令行工具来管理服务：

```
# 启动服务 (调试模式)
php webman vatcron start

# 启动服务 (后台守护模式)
php webman vatcron start -d

# 停止服务
php webman vatcron stop

# 重启服务
php webman vatcron restart

# 查看服务状态
php webman vatcron status
```

### 2. 添加任务

[](#2-添加任务)

#### 方式一：数据库直接添加

[](#方式一数据库直接添加)

直接在 `vat_cron` 表中插入数据即可生效（无需重启服务）：

```
INSERT INTO `vat_crontab`
(`name`, `cron_expression`, `task_type`, `command`, `status`)
VALUES
('测试任务', '*/5 * * * * *', 1, 'echo "Hello Vatcron"', 0);
```

#### 方式二：代码添加

[](#方式二代码添加)

```
use support\Db;

Db::table('vat_crontab')->insert([
    'name' => '清理缓存',
    'cron_expression' => '0 0 2 * * *', // 每天凌晨2点
    'task_type' => 2, // 1:Command, 2:Class, 3:URL, 4:Shell
    'command' => 'App\\Task\\ClearCache::run',
    'status' => 0,
]);
```

### 3. 开发自定义任务

[](#3-开发自定义任务)

只需创建一个普通的 PHP 类，Vatcron 会自动调用指定的方法。

```
namespace App\Task;

class MyTask
{
    public function execute($params = [])
    {
        echo "正在执行自定义任务...\n";
        // 业务逻辑
        return "执行成功";
    }
}
```

在任务配置中：

- Type: `2 (Class)`
- Command: `App\Task\MyTask::execute`

📡 实时日志监控
--------

[](#-实时日志监控)

Vatcron 内置了 WebSocket 服务（默认端口 12348），前端可以连接该端口实时获取任务执行日志。

**WebSocket 地址**: `ws://127.0.0.1:12348`

**订阅协议**:

```
{
    "type": "subscribe",
    "channel": "vatcron:logs"
}
```

**日志数据示例**:

```
{
    "type": "log",
    "data": {
        "task_id": 1,
        "status": "success",
        "output": "Hello Vatcron",
        "duration": 0.05
    }
}
```

🧩 架构图解
------

[](#-架构图解)

 ```
graph TD
    DB[(MySQL Task Table)] -->|Scan| Scheduler[Cron Task Scheduler]
    Scheduler -->|Push| Redis[(Redis Queue)]
    Redis -->|Pop| Executor[Task Executor]
    Executor -->|Run| Worker[Worker Process]
    Executor -->|Log| RedisLog[Redis Log Channel]
    RedisLog -->|Sub| LogServer[WebSocket Log Server]
    LogServer -->|Push| Frontend[Web VUE Admin]
```

      Loading 📄 License
---------

[](#-license)

MIT

---

**Vatcron** - 让 Webman 定时任务管理变得简单而强大。

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance61

Regular maintenance activity

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 96.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b1e67d080b379cae71e19a2d2454d50ef6bb52bd6070a11335dae1136e7c41e?d=identicon)[markowner](/maintainers/markowner)

---

Top Contributors

[![vatick](https://avatars.githubusercontent.com/u/22070538?v=4)](https://github.com/vatick "vatick (26 commits)")[![markowner](https://avatars.githubusercontent.com/u/26614252?v=4)](https://github.com/markowner "markowner (1 commits)")

### Embed Badge

![Health badge](/badges/vat-vatcron/health.svg)

```
[![Health](https://phpackages.com/badges/vat-vatcron/health.svg)](https://phpackages.com/packages/vat-vatcron)
```

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M299](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
