PHPackages                             karlhsu/think-closure-dispatch - 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. [API Development](/categories/api)
4. /
5. karlhsu/think-closure-dispatch

ActiveLibrary[API Development](/categories/api)

karlhsu/think-closure-dispatch
==============================

Laravel-style dispatch with closure support for ThinkPHP

1.1.2(1y ago)021MITPHPPHP &gt;=7.4

Since May 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kar1hsu/think-closure-dispatch)[ Packagist](https://packagist.org/packages/karlhsu/think-closure-dispatch)[ RSS](/packages/karlhsu-think-closure-dispatch/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

ThinkPHP Closure Dispatch
=========================

[](#thinkphp-closure-dispatch)

为 ThinkPHP 提供类似 Laravel 的闭包队列调度功能。

安装
--

[](#安装)

```
composer require karlhsu/think-closure-dispatch
```

要求
--

[](#要求)

- PHP &gt;= 7.4
- ThinkPHP &gt;= 6.0
- ThinkPHP Queue &gt;= 3.0

使用方法
----

[](#使用方法)

### 基本使用

[](#基本使用)

```
use function Karlhsu\ClosureDispatch\dispatch;

// 基本使用
dispatch(function() {
    echo "Hello World";
})->push();

// 延迟执行
dispatch(function() {
    echo "延迟执行的任务";
})->delay(60)->push();  // 60秒后执行

// 指定队列
dispatch(function() {
    echo "在指定队列中执行的任务";
})->onQueue('emails')->push();

// 使用 Carbon 设置延迟时间
use Carbon\Carbon;

dispatch(function() {
    echo "在指定时间执行的任务";
})->delay(Carbon::now()->addMinutes(30))->push();
```

### 配置

[](#配置)

确保项目中已安装并配置了 `topthink/think-queue` 包。在 `config/queue.php` 中配置队列连接信息：

```
