PHPackages                             vzina/hyperf-crontab - 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. vzina/hyperf-crontab

ActiveLibrary

vzina/hyperf-crontab
====================

php hyperf crontab

05PHP

Since Jun 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/vzina/hyperf-crontab)[ Packagist](https://packagist.org/packages/vzina/hyperf-crontab)[ RSS](/packages/vzina-hyperf-crontab/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

定时任务扩展功能
========

[](#定时任务扩展功能)

- 安装

```
composer require vzina/hyperf-crontab
```

- 定义任务服务

```
use Hyperf\Crontab\Crontab;
use Vzina\Crontab\Schedule;
use Vzina\Crontab\ScheduleInterface;

class CustomSchedule extends Schedule implements ScheduleInterface
{
    /**
     * @inheritDoc
     */
    public function getTaskList(): array
    {
        $crontabs = parent::getTaskList();

        $tasks = []; // from db

        if (empty($tasks)) {
            return $crontabs;
        }

        return array_map(static function ($task) { // 格式化任务
            $cron = new Crontab();
            $cron->setName('cron_task_' . $task['id']);
            $cron->setRule($task['cron_spec']);
            if (! empty($task['concurrent'])) {
                $cron->setSingleton(true);
                $cron->setOnOneServer(true);
            }

            $cron->setType($task['task_type']);
            $cron->setCallback($task['command']);

            return $cron;
        }, $tasks) + $crontabs;
    }
}
```

- 配置使用

```
# 使用自定义方式注册任务
#
# config/autoload/dependencies.php
return [
    \Vzina\Crontab\ScheduleInterface::class => \CustomSchedule::class,
    // other...
];

# 通过 config/crontabs.php 来定义定时任务，如配置文件不存在可自行创建：

CustomSchedule::command('foo:bar')->setName('foo-bar')->setRule('* * * * *');
CustomSchedule::call([Foo::class, 'bar'])->setName('foo-bar')->setRule('* * * * *');
CustomSchedule::call(fn() => (new Foo)->bar())->setName('foo-bar')->setRule('* * * * *');
```

- 监听任务执行结果

```
// 定义监听器
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Vzina\Crontab\Event\CrontabExecuted;

/**
 * @Listener()
 */
class CrontabExecutedListener implements ListenerInterface
{
    /**
     * @inheritDoc
     */
    public function listen(): array
    {
        return [
            CrontabExecuted::class,
        ];
    }

    /**
     * @inheritDoc
     */
    public function process(object $event)
    {
        if (! $event instanceof CrontabExecuted) {
            return;
        }

        // todo: 定义处理逻辑
        var_dump($event);
    }
}
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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/248f8ed7469cedfe37c86e79cff2ab49e9f3379b416f29bdf2460527dabfd1ed?d=identicon)[vzina](/maintainers/vzina)

---

Top Contributors

[![vzina](https://avatars.githubusercontent.com/u/7343318?v=4)](https://github.com/vzina "vzina (1 commits)")

### Embed Badge

![Health badge](/badges/vzina-hyperf-crontab/health.svg)

```
[![Health](https://phpackages.com/badges/vzina-hyperf-crontab/health.svg)](https://phpackages.com/packages/vzina-hyperf-crontab)
```

PHPackages © 2026

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