PHPackages                             wolfcode/php-cron - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. wolfcode/php-cron

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wolfcode/php-cron
=================

PHP 8.2+ Cron scheduler with fluent API

00PHP

Since Jun 20Pushed todayCompare

[ Source](https://github.com/wolf-leo/php-cron)[ Packagist](https://packagist.org/packages/wolfcode/php-cron)[ RSS](/packages/wolfcode-php-cron/feed)WikiDiscussions main Synced today

READMEChangelog (3)DependenciesVersions (1)Used By (0)

php-cron
========

[](#php-cron)

PHP 8.2+ 定时任务调度器，提供流畅的 API 和完整的任务生命周期管理。

特性
--

[](#特性)

- **Cron 表达式** — 标准 5 字段，支持 `*/n`、范围、列表、英文月/周名称、`@daily` 别名
- **流畅 API** — `everyMinute()`、`hourly()`、`dailyAt('8:30')`、`weeklyOn('monday')` 等 30+ 方法
- **任务约束** — 时间范围 `between()`、环境过滤 `environments()`、条件 `when()`/`skip()`
- **生命周期钩子** — `before()`、`after()`、`onSuccess()`、`onFailure()`
- **防重叠** — `withoutOverlapping()` 基于文件互斥锁
- **时区支持** — `timezone('Asia/Shanghai')`
- **三种任务类型** — Closure、shell 命令、`Class@method`

安装
--

[](#安装)

```
composer require wolfcode/php-cron
```

快速开始
----

[](#快速开始)

```
use PhpCron\Scheduler;

$scheduler = new Scheduler();

$scheduler->call(function () {
    echo "每分钟执行一次\n";
})->everyMinute()->name('heartbeat');

$scheduler->command('df -h')
    ->hourly()
    ->appendOutputTo(__DIR__ . '/disk-usage.log');

$scheduler->call(function () {
    // 工作日早 9 点发报告
})->dailyAt('9:00')->weekdays()->name('daily-report');

// 运行到期的任务
$scheduler->runDueEvents(new DateTimeImmutable());
```

API 概览
------

[](#api-概览)

### 频次方法

[](#频次方法)

方法cron 表达式`everyMinute()``* * * * *``everyFiveMinutes()``*/5 * * * *``everyFifteenMinutes()``*/15 * * * *``hourly()``0 * * * *``hourlyAt(30)``30 * * * *``daily()``0 0 * * *``dailyAt('8:30')``30 8 * * *``twiceDaily(1, 13)``0 1,13 * * *``weekly()``0 0 * * 0``weeklyOn('monday', '9:00')``0 9 * * 1``monthly()``0 0 1 * *``monthlyOn(15, '14:30')``30 14 15 * *``quarterly()``0 0 1 1,4,7,10 *``yearly()``0 0 1 1 *``weekdays()``0 0 * * 1-5``weekends()``0 0 * * 0,6``lastDayOfMonth()``0 0 28-31 * *` + 过滤器### 约束

[](#约束)

```
->between('9:00', '17:00')     // 仅在 9-17 点之间执行
->unlessBetween('23:00', '6:00') // 不在指定时间段执行
->when(fn() => someCondition())   // 条件为真时执行
->skip(fn() => holidayCheck())    // 条件为真时跳过
->environments('production')      // 仅限指定环境
->timezone('Asia/Shanghai')       // 指定时区
```

### 钩子

[](#钩子)

```
->before(function () { /* 执行前 */ })
->after(function () { /* 执行后（无论成功失败） */ })
->onSuccess(function ($output) { /* 成功时 */ })
->onFailure(function (\Throwable $e) { /* 失败时 */ })
```

### 其他

[](#其他)

```
->withoutOverlapping()           // 防止任务重叠
->evenInMaintenanceMode()        // 维护模式下也执行
->sendOutputTo('/path/to.log')   // 输出到文件
->appendOutputTo('/path/to.log') // 追加到文件
->name('task-name')              // 任务标识
```

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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/120efb64d81a9a893c2b64ca5e85db8574bde280628221e3897b9230487f01fd?d=identicon)[wolfcode](/maintainers/wolfcode)

---

Top Contributors

[![wolf-leo](https://avatars.githubusercontent.com/u/37436228?v=4)](https://github.com/wolf-leo "wolf-leo (3 commits)")

### Embed Badge

![Health badge](/badges/wolfcode-php-cron/health.svg)

```
[![Health](https://phpackages.com/badges/wolfcode-php-cron/health.svg)](https://phpackages.com/packages/wolfcode-php-cron)
```

###  Alternatives

[elhebert/laravel-sri

Subresource Integrity hash generator for laravel

39241.9k](/packages/elhebert-laravel-sri)[mtdowling/burgomaster

Packages up PHP packages into zips and phars

2780.9k12](/packages/mtdowling-burgomaster)[francescomalatesta/laravel-circuit-breaker

A circuit breaker pattern implementation for the Laravel framework

2919.2k2](/packages/francescomalatesta-laravel-circuit-breaker)

PHPackages © 2026

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