PHPackages                             yangweijie/think-worker - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. yangweijie/think-worker

ActiveLibrary[Queues &amp; Workers](/categories/queues)

yangweijie/think-worker
=======================

workerman extend for thinkphp

v5.1.3(1y ago)03Apache-2.0PHPPHP &gt;=8.2

Since Oct 4Pushed 1y agoCompare

[ Source](https://github.com/yangweijie/think-worker)[ Packagist](https://packagist.org/packages/yangweijie/think-worker)[ RSS](/packages/yangweijie-think-worker/feed)WikiDiscussions 5.0 Synced today

READMEChangelog (1)Dependencies (10)Versions (34)Used By (0)

ThinkPHP Workerman 扩展
=====================

[](#thinkphp-workerman-扩展)

交流群：981069000 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://qm.qq.com/q/A8YNpzrzC8)

安装
--

[](#安装)

```
composer require topthink/think-worker

```

说明
--

[](#说明)

> 由于windows下无法在一个文件里启动多个worker，所以本扩展不支持windows平台

使用方法
----

[](#使用方法)

### HttpServer

[](#httpserver)

在命令行启动服务端

```
php think worker

```

然后就可以通过浏览器直接访问当前应用

```
http://localhost:8080

```

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

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

[](#访问静态文件)

> 建议使用nginx来支持静态文件访问，也可使用路由输出文件内容，下面是示例，可参照修改

1. 添加静态文件路由：

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

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

队列支持
----

[](#队列支持)

使用方法见 [think-queue](https://github.com/top-think/think-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服务响应不同的事件

#### 配置

[](#配置)

```
worker.websocket = true 时开启

```

#### 路由定义

[](#路由定义)

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

#### 控制器

[](#控制器)

```
use \think\worker\Websocket;
use \think\worker\websocket\Frame;

class Controller {

    public function action1(){

        return (new \think\worker\response\Websocket())
            ->onOpen(...)
            ->onMessage(function(Websocket $websocket, Frame $frame){
                ...
            })
            ->onClose(...);
    }

    public function action2(){

        return (new \think\worker\response\Websocket())
            ->onOpen(...)
            ->onMessage(function(Websocket $websocket, Frame $frame){
               ...
            })
            ->onClose(...);
    }
}
```

自定义worker
---------

[](#自定义worker)

监听`worker.init`事件 注入`Manager`对象，调用addWorker方法添加

```
use think\worker\Manager;
use \think\worker\Worker;

//...

public function handle(Manager $manager){
   $worker = $manager->addWorker(function(Worker $worker){
        //..其他回调或处理
        //动态添加监听可参考 https://www.workerman.net/doc/workerman/worker/listen.html
    });
}

//...
```

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance50

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 80.8% 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 ~99 days

Recently: every ~44 days

Total

33

Last Release

368d ago

Major Versions

v1.0.1 → v2.0.02018-06-25

v2.0.12 → v3.0.02019-04-23

2.0.x-dev → v3.0.52020-04-30

v3.0.7 → v4.0.02023-07-20

4.0.x-dev → v5.0.0-rc.02024-12-28

### Community

Maintainers

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

---

Top Contributors

[![liu21st](https://avatars.githubusercontent.com/u/1111670?v=4)](https://github.com/liu21st "liu21st (101 commits)")[![yunwuxin](https://avatars.githubusercontent.com/u/2168125?v=4)](https://github.com/yunwuxin "yunwuxin (19 commits)")[![NHZEX](https://avatars.githubusercontent.com/u/14545600?v=4)](https://github.com/NHZEX "NHZEX (3 commits)")[![yangweijie](https://avatars.githubusercontent.com/u/1614114?v=4)](https://github.com/yangweijie "yangweijie (2 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/yangweijie-think-worker/health.svg)

```
[![Health](https://phpackages.com/badges/yangweijie-think-worker/health.svg)](https://phpackages.com/packages/yangweijie-think-worker)
```

###  Alternatives

[drupal/core

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

21866.0M1.7k](/packages/drupal-core)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k251.7M11.5k](/packages/symfony-framework-bundle)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M419](/packages/drupal-core-recommended)[amphp/pipeline

Asynchronous iterators and operators.

7740.0M49](/packages/amphp-pipeline)[api-platform/symfony

Symfony API Platform integration

384.5M127](/packages/api-platform-symfony)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k53](/packages/friendsoftypo3-content-blocks)

PHPackages © 2026

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