PHPackages                             workbunny/event-loop - 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. workbunny/event-loop

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

workbunny/event-loop
====================

A high-performance event loop library for PHP

1.2.1(2y ago)24143MITPHPPHP &gt;=8.1

Since May 26Pushed 2y agoCompare

[ Source](https://github.com/workbunny/event-loop)[ Packagist](https://packagist.org/packages/workbunny/event-loop)[ Docs](https://github.com/workbunny)[ RSS](/packages/workbunny-event-loop/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (8)Used By (0)

[![workbunny](https://camo.githubusercontent.com/e2b1164338390ab45783434659e3e419e0c3b50fbe140c697ba1f82f59015ad6/68747470733a2f2f6368617a366368657a2e636e2f696d616765732f776f726b62756e6e792d6c6f676f2e706e67)](https://camo.githubusercontent.com/e2b1164338390ab45783434659e3e419e0c3b50fbe140c697ba1f82f59015ad6/68747470733a2f2f6368617a366368657a2e636e2f696d616765732f776f726b62756e6e792d6c6f676f2e706e67)

**workbunny/event-loop**

**🐇 A high-performance event loop library for PHP 🐇**

 [ ![Build Status](https://github.com/workbunny/event-loop/actions/workflows/CI.yml/badge.svg) ](https://github.com/workbunny/event-loop/actions) [ ![PHP Version Require](https://camo.githubusercontent.com/521d8a455ed42f13e37be8b4bf5044ac6c97e834eeada47d77abce1e68f1bc46/687474703a2f2f706f7365722e707567782e6f72672f776f726b62756e6e792f6576656e742d6c6f6f702f726571756972652f706870) ](https://github.com/workbunny/event-loop/blob/main/composer.json) [ ![GitHub license](https://camo.githubusercontent.com/88d6aeb1fe2d585695d4b55ecaded0a96a00802cab1365c4b79a2df59917db1f/687474703a2f2f706f7365722e707567782e6f72672f776f726b62756e6e792f6576656e742d6c6f6f702f6c6963656e7365) ](https://github.com/workbunny/event-loop/blob/main/LICENSE)

简介
--

[](#简介)

```
一个事件循环库，目的是为了构建高性能网络应用。

```

使用
--

[](#使用)

注：本文档为 1.2.x 版本，旧版请点击 **[1.1.x 版本](https://github.com/workbunny/event-loop/tree/1.1.x)** 跳转 注：swowloop还未完成单元测试，敬请等待

### 安装

[](#安装)

```
composer require workbunny/event-loop

```

### 创建loop

[](#创建loop)

```
use WorkBunny\EventLoop\Loop;
use WorkBunny\EventLoop\Drivers\NativeLoop;
use WorkBunny\EventLoop\Drivers\EventLoop;
use WorkBunny\EventLoop\Drivers\EvLoop;
use WorkBunny\EventLoop\Drivers\SwowLoop;

// 创建PHP原生loop
$loop = Loop::create(NativeLoop::class);
// 创建ext-event loop
$loop = Loop::create(EventLoop::class);
// 创建ext-ev loop
$loop = Loop::create(EvLoop::class);
// 创建swow loop
$loop = Loop::create(SwowLoop::class);
```

### 注册loop

[](#注册loop)

- 创建 YourLoopClass 实现 LoopInterface
- 调用 Loop::register() 注册 YourLoopClass

```
use WorkBunny\EventLoop\Loop;
// 注册
loop::register(YourLoopClass::class);
// 创建
$yourLoop = Loop::create(YourLoopClass::class);
```

### 创建定时器

[](#创建定时器)

- Future 触发器

```
/**
 * @Future [delay=0.0, repeat=false]
 *  在下一个周期执行，执行一次即自动销毁
 */
$loop->addTimer(0.0, false, function (){ echo 'timer'; }); // loop->run()后立即输出字符串
```

- ReFuture 重复触发器

```
/**
 * @ReFuture [delay=0.0, repeat=0.0]
 *  在每一个周期执行，不会自动销毁
 */
$id = $loop->addTimer(0.0, 0.0, function () use(&$loop, &$id) {
    // 此方法可以实现自我销毁
    $loop->delTimer($id);
});
```

- DelayReFuture 延迟的重复触发器

```
/**
 * @DelayReFuture [delay>0.0, repeat=0.0]
 *  延迟delay秒后每一个周期执行，不会自动销毁
 */
$id = $loop->addTimer(1.0, 0.0, function () use(&$loop, &$id) {
    // 此方法可以实现自我销毁
    $loop->delTimer($id);
});
```

- Delayer 延迟器

```
/**
 * @Delayer [delay>0.0, repeat=false]
 *  延迟delay秒后执行，执行一次即自动销毁
 */
$loop->addTimer(2.0, false, function (){ echo 'timer'; }); // loop->run() 2秒后输出字符串
```

- Timer 定时器

```
/**
 * @Timer [delay=0.0, repeat>0.0]
 *  在下一个周期开始每间隔repeat秒执行，不会自动销毁
 */
$id = $loop->addTimer(0.1, 0.1, function () use(&$loop, &$id) {
    // 此方法可以实现自我销毁
    $loop->delTimer($id);
});
```

- DelayTimer 延迟的定时器

```
/**
 * @DelayTimer [delay>0.0, repeat>0.0]
 *  延迟delay秒后每间隔repeat秒执行，不会自动销毁
 */
$id = $loop->addTimer(0.2, 0.1, function () use(&$loop, &$id) {
    // 此方法可以实现自我销毁
    $loop->delTimer($id);
});
```

### 流事件

[](#流事件)

这里的流是指 **[PHP Streams](https://www.php.net/manual/zh/book.stream.php)**

- 读取流

```
// 创建
$loop->addReadStream(resource, function (resource $stream) { });
// 注意：EvLoop在这里较为特殊，回调函数的入参为EvIo对象
$loop->addReadStream(resource, function (\EvIo $evio) {
    $evio->stream // resource 资源类型
});
// 移除
$loop->delReadStream(resource);
```

- 写入流

```
// 创建
$loop->addWriteStream(resource, function (resource $stream) { });
// 注意：EvLoop在这里较为特殊，回调函数的入参为EvIo对象
$loop->addWriteStream(resource, function (\EvIo $evio) {
    $evio->stream // resource 资源类型
});
// 移除
$loop->delWriteStream(resource);
```

### 信号事件

[](#信号事件)

用于接收系统的信号，比如kill等

```
// 注册
$loop->addSignal(\SIGUSR1, function (){});
// 移除
$loop->delSignal(\SIGUSR1, function (){});
```

### 启动/停止

[](#启动停止)

- 启动

    以下代码会持续阻塞，请放在程序最后一行

```
# 该函数后会阻塞
$loop->loop();

# 该行代码不会执行
var_dump('123');
```

- 停止

    以下代码不会阻塞等待

```
$loop->destroy();

# 该行代码会执行
var_dump('123');
```

---

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~79 days

Recently: every ~117 days

Total

7

Last Release

977d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.4

1.2.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d1b317277226c93c11984f73dfad75533893466b02d06611126aa1687209c6ab?d=identicon)[Chaz6Chez](/maintainers/Chaz6Chez)

---

Top Contributors

[![chaz6chez](https://avatars.githubusercontent.com/u/22535862?v=4)](https://github.com/chaz6chez "chaz6chez (70 commits)")

---

Tags

event-loopphpevent-loopasynchronousreactorext-evext-event

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/workbunny-event-loop/health.svg)

```
[![Health](https://phpackages.com/badges/workbunny-event-loop/health.svg)](https://phpackages.com/packages/workbunny-event-loop)
```

###  Alternatives

[react/react

ReactPHP: Event-driven, non-blocking I/O with PHP.

9.1k3.6M63](/packages/react-react)[react/event-loop

ReactPHP's core reactor event loop that libraries can use for evented I/O.

1.3k139.6M664](/packages/react-event-loop)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[dmamontov/asynctask-7

AsyncTask enables proper and easy use of the thread. This class allows to perform background operations and publish results on the thread without having to manipulate threads and/or handlers.

1313.1k](/packages/dmamontov-asynctask-7)

PHPackages © 2026

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