PHPackages                             iboxs/iboxs-swoole - 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. iboxs/iboxs-swoole

ActiveLibrary[Framework](/categories/framework)

iboxs/iboxs-swoole
==================

Swoole extend for thinkphp

2.0.0(5mo ago)019Apache-2.0PHPPHP ^8.0

Since Sep 25Pushed 5mo agoCompare

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

READMEChangelog (2)Dependencies (11)Versions (3)Used By (0)

ThinkPHP Swoole 扩展
==================

[](#thinkphp-swoole-扩展)

交流群：787100169 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://jq.qq.com/?_wv=1027&k=VRcdnUKL)

安装
--

[](#安装)

首先按照Swoole官网说明安装swoole扩展，然后使用

```
composer require topthink/iboxs-swoole

```

安装swoole扩展。

使用方法
----

[](#使用方法)

直接在命令行下启动HTTP服务端。

```
php iboxs swoole

```

启动完成后，默认会在0.0.0.0:8080启动一个HTTP Server，可以直接访问当前的应用。

swoole的相关参数可以在`config/swoole.php`里面配置（具体参考配置文件内容）。

如果需要使用守护进程方式运行，建议使用supervisor来管理进程

访问静态文件
------

[](#访问静态文件)

> 4.0开始协程风格服务端默认不支持静态文件访问，建议使用nginx来支持静态文件访问，也可使用路由输出文件内容，下面是示例，可参照修改

1. 添加静态文件路由：

```
Route::get('static/:path', function (string $path) {
    $filename = public_path() . $path;
    return new \iboxs\swoole\response\File($filename);
})->pattern(['path' => '.*\.\w+$']);
```

2. 访问路由 `http://localhost/static/文件路径`

队列支持
----

[](#队列支持)

> 4.0开始协程风格服务端没有task进程了，使用think-queue代替

使用方法见 [iboxs-queue](https://github.com/top-iboxs/iboxs-queue)

以下配置代替think-queue里的最后一步:`监听任务并执行`,无需另外起进程执行队列

```
return [
    // ...
    'queue'      => [
        'enable'  => true,
        //键名是队列名称
        'workers' => [
            //下面参数是不设置时的默认配置
            'default'            => [
                'delay'      => 0,
                'sleep'      => 3,
                'tries'      => 0,
                'timeout'    => 60,
                'worker_num' => 1,
            ],
            //使用@符号后面可指定队列使用驱动
            'default@connection' => [
                //此处可不设置任何参数，使用上面的默认配置
            ],
        ],
    ],
    // ...
];
```

### websocket

[](#websocket)

> 新增路由调度的方式，方便实现多个websocket服务

#### 配置

[](#配置)

```
swoole.websocket.route = true 时开启

```

#### 路由定义

[](#路由定义)

```
Route::get('path1','controller/action1');
Route::get('path2','controller/action2');
```

#### 控制器

[](#控制器)

```
use \iboxs\swoole\Websocket;
use \iboxs\swoole\websocket\Event;
use \Swoole\WebSocket\Frame;

class Controller {

    public function action1(){//不可以在这里注入websocket对象

        return \iboxs\swoole\helper\websocket()
            ->onOpen(...)
            ->onMessage(function(Websocket $websocket, Frame $frame){ //只可在事件响应这里注入websocket对象
                ...
            })
            ->onClose(...);
    }

    public function action2(){

        return \iboxs\swoole\helper\websocket()
            ->onOpen(...)
            ->onMessage(function(Websocket $websocket, Frame $frame){
               ...
            })
            ->onClose(...);
    }
}
```

### 流式输出

[](#流式输出)

```
class Controller {

    public function action(){
        return \iboxs\swoole\helper\iterator(value(function(){
            foreach(range(1,10) as $i)
                yield $i;
                sleep(1);//模拟等待
            }
        }));
    }
}
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance72

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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 ~800 days

Total

2

Last Release

160d ago

Major Versions

1.0.0 → 2.0.02025-12-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/89eac34578919508993255948f343a12dd87fbf7f49fe17d147a6715f20da1bd?d=identicon)[itlattice](/maintainers/itlattice)

---

Top Contributors

[![itlattice](https://avatars.githubusercontent.com/u/89900720?v=4)](https://github.com/itlattice "itlattice (2 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/iboxs-iboxs-swoole/health.svg)

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[laravel/dusk

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

1.9k36.7M259](/packages/laravel-dusk)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[topthink/think-swoole

Swoole extend for thinkphp

477174.4k19](/packages/topthink-think-swoole)

PHPackages © 2026

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