From 8e3b2c978e8906114f29705def7b8dfde2a0c124 Mon Sep 17 00:00:00 2001 From: chaz6chez Date: Thu, 10 Oct 2024 16:10:45 +0800 Subject: [PATCH] doc update --- README.md | 51 +- ...ny-WebmanCoroutine-CoroutineWebServer.html | 28 +- ...ny-WebmanCoroutine-Events-SwooleEvent.html | 20 +- ...manCoroutine-Exceptions-PoolException.html | 298 +++++ .../Workbunny-WebmanCoroutine-Factory.html | 103 +- ...bmanCoroutine-Handlers-DefaultHandler.html | 16 +- ...bmanCoroutine-Handlers-HandlerMethods.html | 279 ++++ ...ebmanCoroutine-Handlers-RevoltHandler.html | 586 +++++++++ ...ebmanCoroutine-Handlers-RippleHandler.html | 15 +- ...tine-Handlers-RippleWorkerman5Handler.html | 15 +- ...ebmanCoroutine-Handlers-SwooleHandler.html | 19 +- ...tine-Handlers-SwooleWorkerman5Handler.html | 15 +- ...-WebmanCoroutine-Handlers-SwowHandler.html | 19 +- ...outine-Handlers-SwowWorkerman5Handler.html | 15 +- ...WebmanCoroutine-Utils-Channel-Channel.html | 36 +- ...ils-Channel-Handlers-ChannelInterface.html | 32 +- ...Utils-Channel-Handlers-DefaultChannel.html | 32 +- ...-Utils-Channel-Handlers-RevoltChannel.html | 854 ++++++++++++ ...-Utils-Channel-Handlers-RippleChannel.html | 32 +- ...-Utils-Channel-Handlers-SwooleChannel.html | 32 +- ...ne-Utils-Channel-Handlers-SwowChannel.html | 32 +- ...anCoroutine-Utils-Coroutine-Coroutine.html | 104 +- ...Coroutine-Handlers-CoroutineInterface.html | 26 +- ...s-Coroutine-Handlers-DefaultCoroutine.html | 26 +- ...ls-Coroutine-Handlers-RevoltCoroutine.html | 573 ++++++++ ...ls-Coroutine-Handlers-RippleCoroutine.html | 26 +- ...ls-Coroutine-Handlers-SwooleCoroutine.html | 18 +- ...tils-Coroutine-Handlers-SwowCoroutine.html | 28 +- ...bunny-WebmanCoroutine-Utils-Pool-Pool.html | 1169 +++++++++++++++++ ...WebmanCoroutine-Utils-RegisterMethods.html | 20 +- ...ls-WaitGroup-Handlers-RevoltWaitGroup.html | 709 ++++++++++ ...ls-WaitGroup-Handlers-RippleWaitGroup.html | 12 +- ...ls-WaitGroup-Handlers-SwooleWaitGroup.html | 12 +- ...tils-WaitGroup-Handlers-SwowWaitGroup.html | 16 +- ...anCoroutine-Utils-WaitGroup-WaitGroup.html | 36 +- ...y-WebmanCoroutine-Utils-Worker-Server.html | 157 ++- ...nCoroutine-Utils-Worker-ServerMethods.html | 163 ++- ...y-WebmanCoroutine-Utils-Worker-Worker.html | 12 +- ...nCoroutine-Utils-Worker-WorkerMethods.html | 12 +- docs/doc/webman.md | 19 +- docs/doc/workerman.md | 21 +- docs/files/src-exceptions-poolexception.html | 299 +++++ docs/files/src-handlers-handlermethods.html | 274 ++++ docs/files/src-handlers-revolthandler.html | 299 +++++ docs/files/src-helpers.html | 16 +- ...-utils-channel-handlers-revoltchannel.html | 299 +++++ ...ls-coroutine-handlers-revoltcoroutine.html | 299 +++++ docs/files/src-utils-pool-pool.html | 299 +++++ ...ls-waitgroup-handlers-revoltwaitgroup.html | 299 +++++ docs/files/src/CoroutineWebServer.php.txt | 19 +- docs/files/src/Events/SwooleEvent.php.txt | 47 +- docs/files/src/Events/SwowEvent.php.txt | 4 +- .../src/Exceptions/PoolException.php.txt | 12 + docs/files/src/Factory.php.txt | 19 +- .../files/src/Handlers/DefaultHandler.php.txt | 2 - .../files/src/Handlers/HandlerMethods.php.txt | 22 + docs/files/src/Handlers/RevoltHandler.php.txt | 79 ++ docs/files/src/Handlers/RippleHandler.php.txt | 17 +- .../Handlers/RippleWorkerman5Handler.php.txt | 17 +- docs/files/src/Handlers/SwooleHandler.php.txt | 7 +- .../Handlers/SwooleWorkerman5Handler.php.txt | 6 +- docs/files/src/Handlers/SwowHandler.php.txt | 7 +- .../Handlers/SwowWorkerman5Handler.php.txt | 6 +- docs/files/src/Utils/Channel/Channel.php.txt | 7 +- .../Channel/Handlers/ChannelInterface.php.txt | 3 +- .../Channel/Handlers/DefaultChannel.php.txt | 7 +- .../Channel/Handlers/RevoltChannel.php.txt | 91 ++ .../Channel/Handlers/RippleChannel.php.txt | 7 +- .../Channel/Handlers/SwooleChannel.php.txt | 7 +- .../Channel/Handlers/SwowChannel.php.txt | 5 +- .../src/Utils/Coroutine/Coroutine.php.txt | 15 +- .../Handlers/CoroutineInterface.php.txt | 8 +- .../Handlers/DefaultCoroutine.php.txt | 11 +- .../Handlers/RevoltCoroutine.php.txt | 56 + .../Handlers/RippleCoroutine.php.txt | 27 +- .../Handlers/SwooleCoroutine.php.txt | 14 +- .../Coroutine/Handlers/SwowCoroutine.php.txt | 24 +- docs/files/src/Utils/Pool/Pool.php.txt | 277 ++++ docs/files/src/Utils/RegisterMethods.php.txt | 7 +- .../Handlers/RevoltWaitGroup.php.txt | 75 ++ .../Handlers/RippleWaitGroup.php.txt | 12 +- .../Handlers/SwooleWaitGroup.php.txt | 14 +- .../WaitGroup/Handlers/SwowWaitGroup.php.txt | 13 +- .../Handlers/WaitGroupInterface.php.txt | 2 +- .../src/Utils/WaitGroup/WaitGroup.php.txt | 7 +- .../src/Utils/Worker/AbstractWorker.php.txt | 1 - .../src/Utils/Worker/ServerMethods.php.txt | 48 +- .../src/Utils/Worker/WorkerMethods.php.txt | 2 - docs/files/src/Utils/tools.php.txt | 6 +- docs/files/src/helpers.php.txt | 10 +- docs/indices/files.html | 12 +- docs/js/searchIndex.js | 244 +++- .../workbunny-webmancoroutine-exceptions.html | 2 +- .../workbunny-webmancoroutine-handlers.html | 12 +- ...ebmancoroutine-utils-channel-handlers.html | 2 +- ...mancoroutine-utils-coroutine-handlers.html | 2 +- .../workbunny-webmancoroutine-utils-pool.html | 267 ++++ ...mancoroutine-utils-waitgroup-handlers.html | 2 +- .../workbunny-webmancoroutine-utils.html | 1 + .../namespaces/workbunny-webmancoroutine.html | 16 +- docs/packages/WebmanCoroutine.html | 20 +- 101 files changed, 8766 insertions(+), 606 deletions(-) create mode 100644 docs/classes/Workbunny-WebmanCoroutine-Exceptions-PoolException.html create mode 100644 docs/classes/Workbunny-WebmanCoroutine-Handlers-HandlerMethods.html create mode 100644 docs/classes/Workbunny-WebmanCoroutine-Handlers-RevoltHandler.html create mode 100644 docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-RevoltChannel.html create mode 100644 docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-RevoltCoroutine.html create mode 100644 docs/classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html create mode 100644 docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-RevoltWaitGroup.html create mode 100644 docs/files/src-exceptions-poolexception.html create mode 100644 docs/files/src-handlers-handlermethods.html create mode 100644 docs/files/src-handlers-revolthandler.html create mode 100644 docs/files/src-utils-channel-handlers-revoltchannel.html create mode 100644 docs/files/src-utils-coroutine-handlers-revoltcoroutine.html create mode 100644 docs/files/src-utils-pool-pool.html create mode 100644 docs/files/src-utils-waitgroup-handlers-revoltwaitgroup.html create mode 100644 docs/files/src/Exceptions/PoolException.php.txt create mode 100644 docs/files/src/Handlers/HandlerMethods.php.txt create mode 100644 docs/files/src/Handlers/RevoltHandler.php.txt create mode 100644 docs/files/src/Utils/Channel/Handlers/RevoltChannel.php.txt create mode 100644 docs/files/src/Utils/Coroutine/Handlers/RevoltCoroutine.php.txt create mode 100644 docs/files/src/Utils/Pool/Pool.php.txt create mode 100644 docs/files/src/Utils/WaitGroup/Handlers/RevoltWaitGroup.php.txt create mode 100644 docs/namespaces/workbunny-webmancoroutine-utils-pool.html diff --git a/README.md b/README.md index 036753f..31659b7 100644 --- a/README.md +++ b/README.md @@ -26,15 +26,36 @@ > **🚀🐇 webman-coroutine 是一个支持 workerman / webman 开发框架生态下的协程基建支撑插件** +### 起源 + +- workerman 4.x 及基于其作为运行容器的 webman 框架不支持协程 +- workerman 5.x 及基于其作为运行容器的 webman 框架不具备完备的协程能力 +- workerman / webman 没有一个较为统一的协程使用方式,导致切换协程驱动的开发成本较高,试错成本较高 +- 自行实现协程版worker、server开发成本较高,试错成本较高 + > [workbunny/webman-coroutine 插件诞生缘由及协程开发分享](https://www.workerman.net/a/1769) -**主要实现以下功能**: +### 目的 + +- 提供 workerman/webman 多样的基础协程事件库,兼容支持`workerman 4.x`和`workerman 5.x`的协程驱动 + - [revolt/PHP-fiber](https://github.com/revoltphp/event-loop) + - [swow](https://github.com/swow/swow) + - [swoole](https://github.com/swoole/swoole-src) + - [ripple](https://github.com/cloudtay/ripple) + +- 提供 workerman/webman 统一的协程开发工具,兼容非协程环境 + - 协程通道:[Utils/Channel](https://github.com/workbunny/webman-coroutine/tree/main/src/Utils/Channel) + - 协程等待:[Utils/WaitGroup](https://github.com/workbunny/webman-coroutine/tree/main/src/Utils/WaitGroup) + - 协程:[Utils/Coroutine](https://github.com/workbunny/webman-coroutine/tree/main/src/Utils/Coroutine) + - 协程化Worker:[Utils/Worker](https://github.com/workbunny/webman-coroutine/tree/main/src/Utils/Worker) + - 对象池:[Utils/Pool](https://github.com/workbunny/webman-coroutine/tree/main/src/Utils/Pool) `测试中` -1. 支持`workerman 4.x`的 [swow](https://github.com/swow/swow) 协程驱动能力,兼容`workerman 5.x`版本自带的`swow`协程驱动; -2. 支持`workerman 4.x`的 [swoole](https://github.com/swoole/swoole-src) 协程驱动能力,兼容`workerman 5.x`版本自带的`swoole`协程驱动; -3. 支持 [ripple](https://github.com/cloudtay/ripple) 协程驱动能力,兼容`revolt (PHP-fiber)`协程生态; -4. 提供`coroutine web server` 用于实现具备协程能力的web服务; -5. 支持纯 workerman 环境,支持 webman 开发框架 +### 愿景 + +1. 在 workerman/webman 开发环境下,提供一套简单的协程工具包,降低心智负担。 +2. 在 workerman/webman 开发环境下,尝试实现一套兼容协程与非协程开发的方案,让方案选择和方案逃离更简单,避免更多的焦虑。 +3. 在 workerman/webman 开发环境下,尽可能实现对官方组件的非侵入的协程化改造`(虽然很难,但也想试试)`。 +4. 希望在代码的实现上能够给更多PHP开发带来一些帮助,甚至灵感。 ## 安装 @@ -46,12 +67,7 @@ composer require workbunny/webman-coroutine ## 说明 -1. `workerman 4.x/5.x`驱动下的 webman 框架无法完整使用`swoole`的协程能力,所以使用`CoroutineWebServer`来替代`webman`自带的`webServer` -2. `workerman 4.x`下还未有官方支持的`swow`协程驱动,本插件提供`SwowEvent`事件驱动支撑`workerman 4.x`下的协程能力 -3. 由于配置`event-loop`等操作相较于普通开发会存在一定的心智负担,所以本插件提供了`event_loop()`函数,用于根据当前环境自动选择合适的事件驱动 -4. workerman开发环境下支持使用所有 Utils - -### 目录说明 +### 目录 ``` |-- config # webman 配置文件 @@ -72,11 +88,12 @@ composer require workbunny/webman-coroutine |-- helpers.php # 入口助手 ``` -### 助手函数说明 +### 助手函数 - `event_loop()` 用于自动判断当前环境适合的event loop和协程驱动 > 环境的自动判定按照`Factory::$_handlers`的顺序择先加载 - `package_installed` 用于判定当前环境是否安装对应composer包 +- `wait_for` 用于进程非阻塞地等待对应条件执行(一般是子协程执行结果) - `is_coroutine_env` 用于判断当前环境是否为workbunny协程环境 > 安装workbunny/webman-coroutine后自动会注册环境变量`WORKBUNNY_COROUTINE=1` @@ -85,10 +102,10 @@ composer require workbunny/webman-coroutine | 目录 | 地址 | |:---:|:--------------------------------------------------------------:| | API | [Fucntion-APIs](https://workbunny.github.io/webman-coroutine/) | -| 教程 | [PHP 协程入门](docs/doc/coroutine.md) | -| - | [workerman 环境中使用](docs/doc/workerman.md) | -| - | [webman 框架中使用](docs/doc/webman.md) | -| - | [自定义拓展](docs/doc/custom.md) | +| 教程 | [PHP 协程入门](https://github.com/workbunny/webman-coroutine/tree/main/docs/doc/coroutine.md) | +| - | [workerman 环境中使用](https://github.com/workbunny/webman-coroutine/tree/main/docs/doc/workerman.md) | +| - | [webman 框架中使用](https://github.com/workbunny/webman-coroutine/tree/main/docs/doc/webman.md) | +| - | [自定义拓展](https://github.com/workbunny/webman-coroutine/tree/main/docs/doc/custom.md) | ## ♨️ 相关文章 diff --git a/docs/classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html b/docs/classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html index a09db4d..356ad57 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html +++ b/docs/classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html @@ -232,9 +232,9 @@

获取连接的协程计数

@@ -282,9 +282,9 @@

连接关闭

@@ -339,9 +339,9 @@

连接建立

@@ -396,9 +396,9 @@

@@ -480,9 +480,9 @@

@@ -539,9 +539,9 @@

停止服务

@@ -596,9 +596,9 @@

CoroutineWebServer.php : - 50 + 49 - +

回收连接的协程计数

diff --git a/docs/classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html b/docs/classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html index 5820ed3..f8d82ab 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html @@ -378,9 +378,9 @@

@@ -427,9 +427,9 @@

@@ -493,9 +493,9 @@

@@ -542,9 +542,9 @@

@@ -591,9 +591,9 @@

diff --git a/docs/classes/Workbunny-WebmanCoroutine-Exceptions-PoolException.html b/docs/classes/Workbunny-WebmanCoroutine-Exceptions-PoolException.html new file mode 100644 index 0000000..ff1377b --- /dev/null +++ b/docs/classes/Workbunny-WebmanCoroutine-Exceptions-PoolException.html @@ -0,0 +1,298 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
+

Documentation

+ + + + + +
+ +
+
+ + + + +
+
+ + +
+

+ PoolException + + + extends RuntimeException + + +
+ in package + +
+ + +

+ +
+ + +
+ + + + + + + + + + + + +

+ Table of Contents + + +

+ + + + + + + + + + + + + + + + + + +
+
+
+
+

+        
+ +
+
+ + + +
+
+
+ +
+ On this page + +
    +
  • Table Of Contents
  • +
  • +
      +
    +
  • + + +
+
+ +
+
+
+
+
+

Search results

+ +
+
+
    +
    +
    +
    +
    + + +
    + + + + + + + + diff --git a/docs/classes/Workbunny-WebmanCoroutine-Factory.html b/docs/classes/Workbunny-WebmanCoroutine-Factory.html index 06f3377..ee89ca2 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Factory.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Factory.html @@ -118,9 +118,9 @@

    工厂化启动器

    @@ -160,7 +160,13 @@

    RIPPLE_FIBER -  = 'Psc\Drive\Workerman\PDrive' +  = 'Psc\Drive\Workerman\Drive4' +
    + +
    + RIPPLE_FIBER_5 + +  = 'Psc\Drive\Workerman\Drive5'
    @@ -273,9 +279,9 @@

    @@ -305,9 +311,9 @@

    @@ -316,7 +322,39 @@

    public mixed RIPPLE_FIBER - = 'Psc\Drive\Workerman\PDrive' + = 'Psc\Drive\Workerman\Drive4' + + + + + + + + + + +
    +

    + RIPPLE_FIBER_5 + + +

    + + + + + + + public + mixed + RIPPLE_FIBER_5 + = 'Psc\Drive\Workerman\Drive5' @@ -337,9 +375,9 @@

    @@ -369,9 +407,9 @@

    @@ -401,9 +439,9 @@

    @@ -433,9 +471,9 @@

    @@ -465,9 +503,9 @@

    @@ -511,9 +549,9 @@

    根据事件循环类获取对应处理器

    @@ -567,9 +605,9 @@

    获取所有事件处理器

    @@ -607,9 +645,9 @@

    获取当前事件循环

    @@ -651,9 +689,9 @@

    获取当前使用的处理器类名

    @@ -695,9 +733,9 @@

    初始化

    @@ -741,9 +779,9 @@

    注册事件处理器

    @@ -806,9 +844,9 @@

    注销事件处理器

    @@ -962,6 +1000,7 @@

    Return values
    • REVOLT_FIBER
    • RIPPLE_FIBER
    • +
    • RIPPLE_FIBER_5
    • WORKBUNNY_SWOOLE
    • WORKBUNNY_SWOW
    • WORKERMAN_DEFAULT
    • diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-DefaultHandler.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-DefaultHandler.html index a7e56de..cd72d15 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Handlers-DefaultHandler.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-DefaultHandler.html @@ -122,9 +122,9 @@

      默认处理器,使用workerman基础事件

      @@ -214,9 +214,9 @@

      default handler无需初始化

      @@ -264,9 +264,9 @@

      default handler永远返回true

      @@ -322,9 +322,9 @@

      等待直到回调返回true

      diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-HandlerMethods.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-HandlerMethods.html new file mode 100644 index 0000000..b9c71b3 --- /dev/null +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-HandlerMethods.html @@ -0,0 +1,279 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
      +

      Documentation

      + + + + + +
      + +
      +
      + + + + +
      +
      + + +
      +

      + HandlerMethods +

      + + + + + + + + + + + + +

      + Table of Contents + + +

      + + + + + + + + + + + + + + + + + + + +
      +
      +
      +
      +
      
      +        
      + +
      +
      + + + +
      +
      +
      + +
      + On this page + +
        +
      • Table Of Contents
      • +
      • +
          +
        +
      • +
      +
      + +
      +
      +
      +
      +
      +

      Search results

      + +
      +
      +
        +
        +
        +
        +
        + + +
        + + + + + + + + diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-RevoltHandler.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-RevoltHandler.html new file mode 100644 index 0000000..a94f23a --- /dev/null +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-RevoltHandler.html @@ -0,0 +1,586 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
        +

        Documentation

        + + + + + +
        + +
        +
        + + + + +
        +
        + + +
        +

        + RevoltHandler + + +
        + in package + +
        + + + implements + HandlerInterface + + + uses + HandlerMethods +

        + +
        + + +
        + + + +

        基于Ripple插件的协程处理器,支持PHP-fiber

        + + + + + + + + + +

        + Table of Contents + + +

        + + + +

        + Interfaces + + +

        +
        +
        HandlerInterface
        协程处理器接口
        + + + + + + + +

        + Methods + + +

        +
        +
        + initEnv() + +  : void +
        +
        ripple handler无需初始化
        + +
        + isAvailable() + +  : bool +
        +
        用于判断当前环境是否可用
        + +
        + sleep() + +  : void +
        + +
        + waitFor() + +  : void +
        +
        等待直到回调返回true
        + +
        + + + + + + + +
        +

        + Methods + + +

        +
        +

        + initEnv() + + +

        + + +

        ripple handler无需初始化

        + + + public + static initEnv() : void + +
        +
        + + + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + + +
        +
        +

        + isAvailable() + + +

        + + +

        用于判断当前环境是否可用

        + + + public + static isAvailable() : bool + +
        +
        + + + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + +
        +
        Return values
        + bool + — +

        返回是否可用

        +
        + +
        + +
        +
        +

        + sleep() + + +

        + + + + + public + static sleep(int|float $second) : void + +
        +
        + + +
        Parameters
        +
        +
        + $second + : int|float +
        +
        +

        单位:秒

        +
        + +
        +
        + + + + + + +
        +
        +

        + waitFor() + + +

        + + +

        等待直到回调返回true

        + + + public + static waitFor([Closure|null $closure = null ][, float|int $timeout = -1 ]) : void + +
        +
        + + +
        Parameters
        +
        +
        + $closure + : Closure|null + = null
        +
        +

        返回true或抛出异常则跳出等待

        +
        + +
        +
        + $timeout + : float|int + = -1
        +
        +

        单位:秒| -1:不限制等待时间

        +
        + +
        +
        + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + + +
        +
        + +
        +
        +
        +
        +
        
        +        
        + +
        +
        + + + +
        +
        +
        + +
        + On this page + + +
        + +
        +
        +
        +
        +
        +

        Search results

        + +
        +
        +
          +
          +
          +
          +
          + + +
          + + + + + + + + diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-RippleHandler.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-RippleHandler.html index b4b60f0..62916a2 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Handlers-RippleHandler.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-RippleHandler.html @@ -112,6 +112,9 @@

          implements HandlerInterface + + uses + HandlerMethods

          @@ -122,9 +125,9 @@

          基于Ripple插件的协程处理器,支持PHP-fiber

          @@ -214,9 +217,9 @@

          ripple handler无需初始化

          @@ -322,9 +325,9 @@

          等待直到回调返回true

          diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-RippleWorkerman5Handler.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-RippleWorkerman5Handler.html index c17c606..35e5bc4 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Handlers-RippleWorkerman5Handler.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-RippleWorkerman5Handler.html @@ -112,6 +112,9 @@

          implements HandlerInterface + + uses + HandlerMethods

          @@ -122,9 +125,9 @@

          基于Ripple插件的协程处理器,支持PHP-fiber

          @@ -214,9 +217,9 @@

          ripple handler无需初始化

          @@ -322,9 +325,9 @@

          等待直到回调返回true

          diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwooleHandler.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwooleHandler.html index 2a30c51..9e7e249 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwooleHandler.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwooleHandler.html @@ -112,6 +112,9 @@

          implements HandlerInterface + + uses + HandlerMethods

          @@ -122,9 +125,9 @@

          基于swoole实现的协程处理器

          @@ -214,9 +217,9 @@

          用于环境加载初始化

          @@ -264,9 +267,9 @@

          用于判断当前环境是否可用

          @@ -322,9 +325,9 @@

          等待直到回调返回true

          diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwooleWorkerman5Handler.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwooleWorkerman5Handler.html index 0f11103..3fe53d1 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwooleWorkerman5Handler.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwooleWorkerman5Handler.html @@ -112,6 +112,9 @@

          + + uses + HandlerMethods

        @@ -122,9 +125,9 @@

        基于swoole实现的Workerman5.x版本协程处理器

        @@ -207,9 +210,9 @@

        用于环境加载初始化

        @@ -315,9 +318,9 @@

        等待直到回调返回true

        diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwowHandler.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwowHandler.html index 9599be9..b770738 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwowHandler.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwowHandler.html @@ -112,6 +112,9 @@

        implements HandlerInterface + + uses + HandlerMethods

        @@ -122,9 +125,9 @@

        基于swow实现的协程处理器

        @@ -214,9 +217,9 @@

        swow handler无需初始化

        @@ -264,9 +267,9 @@

        用于判断当前环境是否可用

        @@ -322,9 +325,9 @@

        等待直到回调返回true

        diff --git a/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwowWorkerman5Handler.html b/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwowWorkerman5Handler.html index 562b056..58ae149 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwowWorkerman5Handler.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Handlers-SwowWorkerman5Handler.html @@ -112,6 +112,9 @@

        + + uses + HandlerMethods

        @@ -122,9 +125,9 @@

        基于swow实现的Workerman5.X的协程处理器

        @@ -207,9 +210,9 @@

        swow handler无需初始化

        @@ -315,9 +318,9 @@

        等待直到回调返回true

        diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Channel.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Channel.html index fe1bf0e..b0aa8a2 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Channel.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Channel.html @@ -123,9 +123,9 @@

        @@ -276,9 +276,9 @@

        代理调用ChannelInterface方法

        @@ -329,9 +329,9 @@

        构造方法

        @@ -375,9 +375,9 @@

        析构方法

        @@ -485,9 +485,9 @@

        获取指定handler 或 获取所有

        @@ -710,9 +710,9 @@

        注册

        @@ -767,9 +767,9 @@

        @@ -830,9 +830,9 @@

        注销

        @@ -880,9 +880,9 @@

        diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-ChannelInterface.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-ChannelInterface.html index 4a3e2ab..3f97181 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-ChannelInterface.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-ChannelInterface.html @@ -230,9 +230,9 @@

        初始化通道

        @@ -278,9 +278,9 @@

        摧毁通道

        @@ -314,9 +314,9 @@

        获取通道容量

        @@ -354,9 +354,9 @@

        关闭通道

        @@ -390,9 +390,9 @@

        通道是否为空

        @@ -430,9 +430,9 @@

        通道是否满

        @@ -470,9 +470,9 @@

        获取一个数据

        @@ -526,9 +526,9 @@

        推送一个数据

        diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-DefaultChannel.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-DefaultChannel.html index af556d9..75721a6 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-DefaultChannel.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-DefaultChannel.html @@ -250,9 +250,9 @@

        初始化通道

        @@ -312,9 +312,9 @@

        摧毁通道

        @@ -362,9 +362,9 @@

        获取通道容量

        @@ -416,9 +416,9 @@

        关闭通道

        @@ -466,9 +466,9 @@

        通道是否为空

        @@ -520,9 +520,9 @@

        通道是否满

        @@ -574,9 +574,9 @@

        获取一个数据

        @@ -630,9 +630,9 @@

        推送一个数据

        diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-RevoltChannel.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-RevoltChannel.html new file mode 100644 index 0000000..66588ba --- /dev/null +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-RevoltChannel.html @@ -0,0 +1,854 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
        +

        Documentation

        + + + + + +
        + +
        +
        + + + + +
        +
        + + +
        +

        + RevoltChannel + + +
        + in package + +
        + + + implements + ChannelInterface + +

        + +
        + + +
        + + + + + + + + + + + + +

        + Table of Contents + + +

        + + + +

        + Interfaces + + +

        +
        +
        ChannelInterface
        + + + + + + + +

        + Methods + + +

        +
        +
        + __construct() + +  : mixed +
        +
        初始化通道
        + +
        + __destruct() + +  : mixed +
        +
        摧毁通道
        + +
        + capacity() + +  : int +
        +
        获取通道容量
        + +
        + close() + +  : void +
        +
        关闭通道
        + +
        + isEmpty() + +  : bool +
        +
        通道是否为空
        + +
        + isFull() + +  : bool +
        +
        通道是否满
        + +
        + pop() + +  : mixed +
        +
        获取一个数据
        + +
        + push() + +  : mixed +
        +
        推送一个数据
        + +
        + + + + + + + +
        +

        + Methods + + +

        +
        +

        + __construct() + + +

        + + +

        初始化通道

        + + + public + __construct([int $capacity = -1 ]) : mixed + +
        +
        + + +
        Parameters
        +
        +
        + $capacity + : int + = -1
        +
        +

        初始容量

        +
        + +
        +
        + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + + +
        +
        +

        + __destruct() + + +

        + + +

        摧毁通道

        + + + public + __destruct() : mixed + +
        +
        + + + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + + +
        +
        +

        + capacity() + + +

        + + +

        获取通道容量

        + + + public + capacity() : int + +
        +
        + + + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + +
        +
        Return values
        + int +
        + +
        +
        +

        + close() + + +

        + + +

        关闭通道

        + + + public + close() : void + +
        +
        + + + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + + +
        +
        +

        + isEmpty() + + +

        + + +

        通道是否为空

        + + + public + isEmpty() : bool + +
        +
        + + + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + +
        +
        Return values
        + bool +
        + +
        +
        +

        + isFull() + + +

        + + +

        通道是否满

        + + + public + isFull() : bool + +
        +
        + + + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + +
        +
        Return values
        + bool +
        + +
        +
        +

        + pop() + + +

        + + +

        获取一个数据

        + + + public + pop([int|float $timeout = -1 ]) : mixed + +
        +
        + + +
        Parameters
        +
        +
        + $timeout + : int|float + = -1
        +
        +

        单位:秒

        +
        + +
        +
        + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + +
        +
        Return values
        + mixed + — +

        false:通道关闭

        +
        + +
        + +
        +
        +

        + push() + + +

        + + +

        推送一个数据

        + + + public + push(mixed $data[, int|float $timeout = -1 ]) : mixed + +
        +
        + + +
        Parameters
        +
        +
        + $data + : mixed +
        +
        + +
        +
        + $timeout + : int|float + = -1
        +
        +

        单位:秒

        +
        + +
        +
        + + +
        + Tags + + +
        +
        +
        + inheritdoc +
        +
        + + +
        +
        + + + + +
        +
        + +
        +
        +
        +
        +
        
        +        
        + +
        +
        + + + +
        +
        +
        + +
        + On this page + + +
        + +
        +
        +
        +
        +
        +

        Search results

        + +
        +
        +
          +
          +
          +
          +
          + + +
          + + + + + + + + diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-RippleChannel.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-RippleChannel.html index f5bd0f3..d5611a7 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-RippleChannel.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-RippleChannel.html @@ -250,9 +250,9 @@

          初始化通道

          @@ -312,9 +312,9 @@

          摧毁通道

          @@ -362,9 +362,9 @@

          获取通道容量

          @@ -416,9 +416,9 @@

          关闭通道

          @@ -466,9 +466,9 @@

          通道是否为空

          @@ -520,9 +520,9 @@

          通道是否满

          @@ -574,9 +574,9 @@

          获取一个数据

          @@ -644,9 +644,9 @@

          推送一个数据

          diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-SwooleChannel.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-SwooleChannel.html index cb63e27..62cc85f 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-SwooleChannel.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-SwooleChannel.html @@ -250,9 +250,9 @@

          初始化通道

          @@ -312,9 +312,9 @@

          摧毁通道

          @@ -362,9 +362,9 @@

          获取通道容量

          @@ -416,9 +416,9 @@

          关闭通道

          @@ -466,9 +466,9 @@

          通道是否为空

          @@ -520,9 +520,9 @@

          通道是否满

          @@ -574,9 +574,9 @@

          获取一个数据

          @@ -644,9 +644,9 @@

          推送一个数据

          diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-SwowChannel.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-SwowChannel.html index 23e0ef2..0b82893 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-SwowChannel.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Channel-Handlers-SwowChannel.html @@ -250,9 +250,9 @@

          初始化通道

          @@ -312,9 +312,9 @@

          摧毁通道

          @@ -362,9 +362,9 @@

          获取通道容量

          @@ -416,9 +416,9 @@

          关闭通道

          @@ -466,9 +466,9 @@

          通道是否为空

          @@ -520,9 +520,9 @@

          通道是否满

          @@ -574,9 +574,9 @@

          获取一个数据

          @@ -644,9 +644,9 @@

          推送一个数据

          diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Coroutine.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Coroutine.html index 9e1e227..e7963aa 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Coroutine.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Coroutine.html @@ -123,9 +123,9 @@

          @@ -170,12 +170,14 @@

           : mixed +
          构造方法
          __destruct()  : mixed
          +
          析构
          getHandler() @@ -184,6 +186,12 @@

          获取指定handler 或 获取所有
          +
          + id() + +  : string|int +
          +
          origin() @@ -244,9 +252,9 @@

          代理调用WaitGroupInterface方法

          @@ -297,12 +305,13 @@

          - +

          构造方法

          + public __construct(Closure $func) : mixed @@ -323,6 +332,20 @@

          Parameters
          +
          + Tags + + +
          +
          +
          + link +
          +
          + CoroutineInterface::__construct + +
          +
          @@ -342,12 +365,13 @@

          - +

          析构

          + public __destruct() : mixed @@ -377,9 +401,9 @@

          获取指定handler 或 获取所有

          @@ -412,6 +436,45 @@

          Return values
          array<string|int, mixed> + +
          +

          + id() + + +

          + + + + + public + id() : string|int + +
          +
          + + + + + + + +
          +
          Return values
          + string|int +
          +

          注册

          @@ -519,9 +582,9 @@

          @@ -582,9 +645,9 @@

          注销

          @@ -632,9 +695,9 @@

          @@ -798,6 +861,7 @@

          Return values
        • __construct()
        • __destruct()
        • getHandler()
        • +
        • id()
        • origin()
        • register()
        • registerVerify()
        • diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-CoroutineInterface.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-CoroutineInterface.html index fd34180..a80c8a3 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-CoroutineInterface.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-CoroutineInterface.html @@ -164,7 +164,7 @@

          id() -  : string|int +  : string|int|null
          获取协程id
          @@ -202,9 +202,9 @@

          创建协程

          @@ -224,7 +224,9 @@

          Parameters
          : Closure
          - +

          = function (mixed $coroutineId) }

          +
          +
          @@ -248,9 +250,9 @@

          销毁协程

          @@ -284,16 +286,16 @@

          获取协程id

          public - id() : string|int + id() : string|int|null
          @@ -306,7 +308,7 @@

          Return values
          - string|int + string|int|null
          @@ -324,9 +326,9 @@

          获取协程原始返回

          diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-DefaultCoroutine.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-DefaultCoroutine.html index bda9dee..6bd29a3 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-DefaultCoroutine.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-DefaultCoroutine.html @@ -183,7 +183,7 @@

          id() -  : string|int +  : string|int|null
          获取协程id
          @@ -222,9 +222,9 @@

          创建协程

          @@ -244,7 +244,9 @@

          Parameters
          : Closure
          - +

          = function (mixed $coroutineId) }

          +
          +
          @@ -282,9 +284,9 @@

          销毁协程

          @@ -332,16 +334,16 @@

          获取协程id

          public - id() : string|int + id() : string|int|null
          @@ -368,7 +370,7 @@

          Return values
          - string|int + string|int|null
          @@ -386,9 +388,9 @@

          获取协程原始返回

          diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-RevoltCoroutine.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-RevoltCoroutine.html new file mode 100644 index 0000000..3a524ad --- /dev/null +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-RevoltCoroutine.html @@ -0,0 +1,573 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
          +

          Documentation

          + + + + + +
          + +
          +
          + + + + +
          +
          + + +
          +

          + RevoltCoroutine + + +
          + in package + +
          + + + implements + CoroutineInterface + +

          + +
          + + +
          + + + + + + + + + + + + +

          + Table of Contents + + +

          + + + +

          + Interfaces + + +

          +
          +
          CoroutineInterface
          + + + + + + + +

          + Methods + + +

          +
          +
          + __construct() + +  : mixed +
          +
          创建协程
          + +
          + __destruct() + +  : mixed +
          +
          销毁协程
          + +
          + id() + +  : string|int|null +
          +
          获取协程id
          + +
          + origin() + +  : mixed +
          +
          获取协程原始返回
          + +
          + + + + + + + +
          +

          + Methods + + +

          +
          +

          + __construct() + + +

          + + +

          创建协程

          + + + public + __construct(Closure $func) : mixed + +
          +
          + + +
          Parameters
          +
          +
          + $func + : Closure +
          +
          + +
          +
          + + +
          + Tags + + +
          +
          +
          + inheritdoc +
          +
          + + +
          +
          + + + + +
          +
          +

          + __destruct() + + +

          + + +

          销毁协程

          + + + public + __destruct() : mixed + +
          +
          + + + + +
          + Tags + + +
          +
          +
          + inheritdoc +
          +
          + + +
          +
          + + + + +
          +
          +

          + id() + + +

          + + +

          获取协程id

          + + + public + id() : string|int|null + +
          +
          + + + + +
          + Tags + + +
          +
          +
          + inheritdoc +
          +
          + + +
          +
          + + + +
          +
          Return values
          + string|int|null +
          + +
          +
          +

          + origin() + + +

          + + +

          获取协程原始返回

          + + + public + origin() : mixed + +
          +
          + + + + +
          + Tags + + +
          +
          +
          + inheritdoc +
          +
          + + +
          +
          + + + + +
          +
          + +
          +
          +
          +
          +
          
          +        
          + +
          +
          + + + +
          +
          +
          + +
          + On this page + + +
          + +
          +
          +
          +
          +
          +

          Search results

          + +
          +
          +
            +
            +
            +
            +
            + + +
            + + + + + + + + diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-RippleCoroutine.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-RippleCoroutine.html index 1c00037..91070c6 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-RippleCoroutine.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-RippleCoroutine.html @@ -124,9 +124,9 @@

            @@ -183,7 +183,7 @@

            id() -  : string|int +  : string|int|null
            获取协程id
            @@ -222,9 +222,9 @@

            创建协程

            @@ -282,9 +282,9 @@

            销毁协程

            @@ -332,16 +332,16 @@

            获取协程id

            public - id() : string|int + id() : string|int|null
            @@ -368,7 +368,7 @@

            Return values
            - string|int + string|int|null
            @@ -386,9 +386,9 @@

            获取协程原始返回

            diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwooleCoroutine.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwooleCoroutine.html index 9a43a56..36c53e4 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwooleCoroutine.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwooleCoroutine.html @@ -183,7 +183,7 @@

            id() -  : string|int +  : string|int|null
            获取协程id
            @@ -282,9 +282,9 @@

            销毁协程

            @@ -332,16 +332,16 @@

            获取协程id

            public - id() : string|int + id() : string|int|null
            @@ -368,7 +368,7 @@

            Return values
            - string|int + string|int|null
            @@ -386,9 +386,9 @@

            获取协程原始返回

            diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwowCoroutine.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwowCoroutine.html index 2563d9a..70ef0ee 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwowCoroutine.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwowCoroutine.html @@ -183,7 +183,7 @@

            id() -  : string|int +  : string|int|null
            获取协程id
            @@ -222,9 +222,9 @@

            创建协程

            @@ -244,7 +244,9 @@

            Parameters
            : Closure
            - +

            = function (mixed $coroutineId) }

            +
            +
            @@ -256,7 +258,7 @@
            - inheritdoc + inheritDoc
            @@ -282,9 +284,9 @@

            销毁协程

            @@ -332,16 +334,16 @@

            获取协程id

            public - id() : string|int + id() : string|int|null
            @@ -368,7 +370,7 @@

            Return values
            - string|int + string|int|null
            @@ -386,9 +388,9 @@

            获取协程原始返回

            diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html new file mode 100644 index 0000000..a5bfcdc --- /dev/null +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html @@ -0,0 +1,1169 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
            +

            Documentation

            + + + + + +
            + +
            +
            + + + + +
            +
            + + +
            +

            + Pool + + +
            + in package + +
            + + +

            + +
            + + +
            + + + + + + + + + + + + +

            + Table of Contents + + +

            + + + + + + + + + + +

            + Methods + + +

            +
            +
            + __construct() + +  : mixed +
            +
            构造
            + +
            + __destruct() + +  : mixed +
            +
            析构等待销毁
            + +
            + create() + +  : array<string|int, Pool> +
            +
            创建
            + +
            + destroy() + +  : void +
            +
            回收
            + +
            + get() + +  : Pool|array<string|int, Pool>|null +
            +
            获取
            + +
            + getElement() + +  : resource|object|array<string|int, mixed>|mixed +
            +
            获取元素
            + +
            + getIndex() + +  : int +
            +
            所在区域的索引
            + +
            + getName() + +  : string +
            +
            获取所在区域名称
            + +
            + idle() + +  : Pool|null +
            +
            获取空闲池
            + +
            + isForce() + +  : bool +
            +
            是否强制回收
            + +
            + isIdle() + +  : bool +
            +
            是否闲置
            + +
            + setForce() + +  : void +
            +
            设置强制回收
            + +
            + setIdle() + +  : void +
            +
            设置状态
            + +
            + wait() + +  : void +
            +
            等待至闲置
            + +
            + waitForIdle() + +  : mixed +
            +
            等待空闲并执行
            + +
            + + + + + + + +
            +

            + Methods + + +

            +
            +

            + __construct() + + +

            + + +

            构造

            + + + public + __construct(string $name, int $index, object|array<string|int, mixed>|resource|mixed $element) : mixed + +
            +
            + + +
            Parameters
            +
            +
            + $name + : string +
            +
            + +
            +
            + $index + : int +
            +
            +

            索引

            +
            + +
            +
            + $element + : object|array<string|int, mixed>|resource|mixed +
            +
            + +
            +
            + + + + + + +
            +
            +

            + __destruct() + + +

            + + +

            析构等待销毁

            + + + public + __destruct() : mixed + +
            +
            + + + + + + + + +
            +
            +

            + create() + + +

            + + +

            创建

            + + + public + static create(string $name, int $count, mixed $element) : array<string|int, Pool> + +
            +
            + + +
            Parameters
            +
            +
            + $name + : string +
            +
            + +
            +
            + $count + : int +
            +
            + +
            +
            + $element + : mixed +
            +
            + +
            +
            + + + + + +
            +
            Return values
            + array<string|int, Pool> +
            + +
            +
            +

            + destroy() + + +

            + + +

            回收

            + + + public + static destroy(string $name, int|null $index[, bool $force = false ]) : void + +
            +
            + + +
            Parameters
            +
            +
            + $name + : string +
            +
            + +
            +
            + $index + : int|null +
            +
            + +
            +
            + $force + : bool + = false
            +
            + +
            +
            + + + + + + +
            +
            +

            + get() + + +

            + + +

            获取

            + + + public + static get(string $name, int|null $index) : Pool|array<string|int, Pool>|null + +
            +
            + + +
            Parameters
            +
            +
            + $name + : string +
            +
            + +
            +
            + $index + : int|null +
            +
            + +
            +
            + + + + + +
            +
            Return values
            + Pool|array<string|int, Pool>|null +
            + +
            +
            +

            + getElement() + + +

            + + +

            获取元素

            + + + public + getElement() : resource|object|array<string|int, mixed>|mixed + +
            +
            + + + + + + + +
            +
            Return values
            + resource|object|array<string|int, mixed>|mixed +
            + +
            +
            +

            + getIndex() + + +

            + + +

            所在区域的索引

            + + + public + getIndex() : int + +
            +
            + + + + + + + +
            +
            Return values
            + int +
            + +
            +
            +

            + getName() + + +

            + + +

            获取所在区域名称

            + + + public + getName() : string + +
            +
            + + + + + + + +
            +
            Return values
            + string +
            + +
            +
            +

            + idle() + + +

            + + +

            获取空闲池

            + + + public + static idle(string $name) : Pool|null + +
            +
            + + +
            Parameters
            +
            +
            + $name + : string +
            +
            + +
            +
            + + + + + +
            +
            Return values
            + Pool|null +
            + +
            +
            +

            + isForce() + + +

            + + +

            是否强制回收

            + + + public + isForce() : bool + +
            +
            + + + + + + + +
            +
            Return values
            + bool +
            + +
            +
            +

            + isIdle() + + +

            + + +

            是否闲置

            + + + public + isIdle() : bool + +
            +
            + + + + + + + +
            +
            Return values
            + bool +
            + +
            +
            +

            + setForce() + + +

            + + +

            设置强制回收

            + + + public + setForce(bool $force) : void + +
            +
            + + +
            Parameters
            +
            +
            + $force + : bool +
            +
            + +
            +
            + + + + + + +
            +
            +

            + setIdle() + + +

            + + +

            设置状态

            + + + public + setIdle(bool $idle) : void + +
            +
            + + +
            Parameters
            +
            +
            + $idle + : bool +
            +
            + +
            +
            + + + + + + +
            +
            +

            + wait() + + +

            + + +

            等待至闲置

            + + + public + wait([Closure|null $closure = null ]) : void + +
            +
            + + +
            Parameters
            +
            +
            + $closure + : Closure|null + = null
            +
            + +
            +
            + + + + + + +
            +
            +

            + waitForIdle() + + +

            + + +

            等待空闲并执行

            + + + public + static waitForIdle(string $name, Closure $closure[, int $timeout = -1 ]) : mixed + +
            +
            + + +
            Parameters
            +
            +
            + $name + : string +
            +
            +

            池区域

            +
            + +
            +
            + $closure + : Closure +
            +
            +

            被执行函数 = function (Pool $pool) }

            +
            + +
            +
            + $timeout + : int + = -1
            +
            +

            超时时间

            +
            + +
            +
            + + + + + + +
            +
            + +
            +
            +
            +
            +
            
            +        
            + +
            +
            + + + +
            +
            +
            + +
            + On this page + + +
            + +
            +
            +
            +
            +
            +

            Search results

            + +
            +
            +
              +
              +
              +
              +
              + + +
              + + + + + + + + diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-RegisterMethods.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-RegisterMethods.html index 89070d8..10bf233 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-RegisterMethods.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-RegisterMethods.html @@ -203,9 +203,9 @@

              获取指定handler 或 获取所有

              @@ -253,9 +253,9 @@

              注册

              @@ -310,9 +310,9 @@

              注册校验

              @@ -383,9 +383,9 @@

              注销

              @@ -433,9 +433,9 @@

              注销执行

              diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-RevoltWaitGroup.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-RevoltWaitGroup.html new file mode 100644 index 0000000..fc3f5d3 --- /dev/null +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-RevoltWaitGroup.html @@ -0,0 +1,709 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
              +

              Documentation

              + + + + + +
              + +
              +
              + + + + +
              +
              + + +
              +

              + RevoltWaitGroup + + +
              + in package + +
              + + + implements + WaitGroupInterface + +

              + +
              + + +
              + + + + + + + + + + + + +

              + Table of Contents + + +

              + + + +

              + Interfaces + + +

              +
              +
              WaitGroupInterface
              + + + + + + + +

              + Methods + + +

              +
              +
              + __construct() + +  : mixed +
              +
              初始化
              + +
              + __destruct() + +  : mixed +
              +
              销毁
              + +
              + add() + +  : bool +
              +
              增加一个计数
              + +
              + count() + +  : int +
              +
              返回计数
              + +
              + done() + +  : bool +
              +
              完成一个计数
              + +
              + wait() + +  : void +
              +
              阻塞等待
              + +
              + + + + + + + +
              +

              + Methods + + +

              +
              +

              + __construct() + + +

              + + +

              初始化

              + + + public + __construct() : mixed + +
              +
              + + + + +
              + Tags + + +
              +
              +
              + inheritdoc +
              +
              + + +
              +
              + + + + +
              +
              +

              + __destruct() + + +

              + + +

              销毁

              + + + public + __destruct() : mixed + +
              +
              + + + + +
              + Tags + + +
              +
              +
              + inheritdoc +
              +
              + + +
              +
              + + + + +
              +
              +

              + add() + + +

              + + +

              增加一个计数

              + + + public + add([int $delta = 1 ]) : bool + +
              +
              + + +
              Parameters
              +
              +
              + $delta + : int + = 1
              +
              + +
              +
              + + +
              + Tags + + +
              +
              +
              + inheritdoc +
              +
              + + +
              +
              + + + +
              +
              Return values
              + bool +
              + +
              +
              +

              + count() + + +

              + + +

              返回计数

              + + + public + count() : int + +
              +
              + + + + +
              + Tags + + +
              +
              +
              + inheritdoc +
              +
              + + +
              +
              + + + +
              +
              Return values
              + int +
              + +
              +
              +

              + done() + + +

              + + +

              完成一个计数

              + + + public + done() : bool + +
              +
              + + + + +
              + Tags + + +
              +
              +
              + inheritdoc +
              +
              + + +
              +
              + + + +
              +
              Return values
              + bool +
              + +
              +
              +

              + wait() + + +

              + + +

              阻塞等待

              + + + public + wait([int|float $timeout = -1 ]) : void + +
              +
              + + +
              Parameters
              +
              +
              + $timeout + : int|float + = -1
              +
              +

              单位:秒

              +
              + +
              +
              + + +
              + Tags + + +
              +
              +
              + inheritdoc +
              +
              + + +
              +
              + + + + +
              +
              + +
              +
              +
              +
              +
              
              +        
              + +
              +
              + + + +
              +
              +
              + +
              + On this page + + +
              + +
              +
              +
              +
              +
              +

              Search results

              + +
              +
              +
                +
                +
                +
                +
                + + +
                + + + + + + + + diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-RippleWaitGroup.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-RippleWaitGroup.html index ec792a2..554bfd5 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-RippleWaitGroup.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-RippleWaitGroup.html @@ -400,9 +400,9 @@

                返回计数

                @@ -454,9 +454,9 @@

                完成一个计数

                @@ -508,9 +508,9 @@

                阻塞等待

                diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-SwooleWaitGroup.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-SwooleWaitGroup.html index 3dee810..2654f59 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-SwooleWaitGroup.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-SwooleWaitGroup.html @@ -400,9 +400,9 @@

                返回计数

                @@ -454,9 +454,9 @@

                完成一个计数

                @@ -508,9 +508,9 @@

                阻塞等待

                diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-SwowWaitGroup.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-SwowWaitGroup.html index c7a387a..99036f7 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-SwowWaitGroup.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-Handlers-SwowWaitGroup.html @@ -336,9 +336,9 @@

                增加一个计数

                @@ -400,9 +400,9 @@

                返回计数

                @@ -454,9 +454,9 @@

                完成一个计数

                @@ -508,9 +508,9 @@

                阻塞等待

                diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-WaitGroup.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-WaitGroup.html index 9ae0a08..06c9fad 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-WaitGroup.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-WaitGroup-WaitGroup.html @@ -123,9 +123,9 @@

                @@ -264,9 +264,9 @@

                代理调用WaitGroupInterface方法

                @@ -317,9 +317,9 @@

                构造方法

                @@ -353,9 +353,9 @@

                析构方法

                @@ -516,9 +516,9 @@

                获取指定handler 或 获取所有

                @@ -566,9 +566,9 @@

                注册

                @@ -623,9 +623,9 @@

                @@ -686,9 +686,9 @@

                注销

                @@ -736,9 +736,9 @@

                diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-Server.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-Server.html index 4b11749..283e95d 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-Server.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-Server.html @@ -162,6 +162,20 @@

                +

                + Properties + + +

                +
                +
                + $consumerCount + +  : int +
                +
                请求消费者协程数量,0为无限
                + +

                Methods @@ -215,6 +229,13 @@

                设置连接on message是否等待
                +
                + unsetConnectionCoroutineCount() + +  : void +
                +
                回收连接的协程计数
                +

                @@ -222,6 +243,51 @@

                +
                +

                + Properties + + +

                +
                +

                + $consumerCount + + + + +

                + + +

                请求消费者协程数量,0为无限

                + + + + public + static int + $consumerCount + = 0 + + + + + + + +
                +

                @@ -243,9 +309,9 @@

                初始化服务

                @@ -279,9 +345,9 @@

                获取连接的协程计数

                @@ -329,9 +395,9 @@

                @@ -382,9 +448,9 @@

                @@ -435,9 +501,9 @@

                @@ -488,9 +554,9 @@

                设置连接创建/关闭协程化

                @@ -534,9 +600,9 @@

                设置连接on message是否等待

                @@ -565,6 +631,59 @@

                Parameters
                + +
                +

                + unsetConnectionCoroutineCount() + + +

                + + +

                回收连接的协程计数

                + + + public + static unsetConnectionCoroutineCount(string $connectionId[, bool $force = false ]) : void + +
                +
                + + +
                Parameters
                +
                +
                + $connectionId + : string +
                +
                + +
                +
                + $force + : bool + = false
                +
                + +
                +
                + + + + + +
                @@ -671,10 +790,17 @@

                Parameters
              • Table Of Contents
              • +
              • Properties
              • +
              • + +
              • Methods
              • @@ -686,6 +812,7 @@
                Parameters
              • getParentOnMessage()
              • setConnectionCoroutine()
              • setConnectionOnMessageWait()
              • +
              • unsetConnectionCoroutineCount()
              • diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-ServerMethods.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-ServerMethods.html index e662c64..bd532ca 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-ServerMethods.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-ServerMethods.html @@ -105,9 +105,9 @@

                @@ -133,6 +133,20 @@

                +

                + Properties + + +

                +
                +
                + $consumerCount + +  : int +
                +
                请求消费者协程数量,0为无限
                + +

                Methods @@ -186,6 +200,13 @@

                设置连接on message是否等待
                +
                + unsetConnectionCoroutineCount() + +  : void +
                +
                回收连接的协程计数
                + @@ -194,6 +215,51 @@

                +
                +

                + Properties + + +

                +
                +

                + $consumerCount + + + + +

                + + +

                请求消费者协程数量,0为无限

                + + + + public + static int + $consumerCount + = 0 + + + + + + + +
                +

                @@ -215,9 +281,9 @@

                初始化服务

                @@ -251,9 +317,9 @@

                获取连接的协程计数

                @@ -301,9 +367,9 @@

                @@ -354,9 +420,9 @@

                @@ -407,9 +473,9 @@

                @@ -460,9 +526,9 @@

                设置连接创建/关闭协程化

                @@ -506,9 +572,9 @@

                设置连接on message是否等待

                @@ -537,6 +603,59 @@

                Parameters
                + +
                +

                + unsetConnectionCoroutineCount() + + +

                + + +

                回收连接的协程计数

                + + + public + static unsetConnectionCoroutineCount(string $connectionId[, bool $force = false ]) : void + +
                +
                + + +
                Parameters
                +
                +
                + $connectionId + : string +
                +
                + +
                +
                + $force + : bool + = false
                +
                + +
                +
                + + + + + +
                @@ -643,10 +762,17 @@

                Parameters
              • Table Of Contents
              • +
              • +
              • Properties
              • +
              • +
              • -
              • Methods
              • +
              • Methods
              • diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-Worker.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-Worker.html index c332c62..1a394fa 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-Worker.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-Worker.html @@ -208,9 +208,9 @@

                @@ -243,9 +243,9 @@

                @@ -282,9 +282,9 @@

                diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-WorkerMethods.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-WorkerMethods.html index 716fb62..3e023e1 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-WorkerMethods.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Worker-WorkerMethods.html @@ -187,9 +187,9 @@

                @@ -222,9 +222,9 @@

                @@ -261,9 +261,9 @@

                diff --git a/docs/doc/webman.md b/docs/doc/webman.md index 388c4c8..2bbc449 100644 --- a/docs/doc/webman.md +++ b/docs/doc/webman.md @@ -8,7 +8,6 @@ - enable : (true/false), 是否启用协程webServer - port : (int), 协程webServer默认端口 -- channel_size : (int), 每个connection的channel容量 - consumer_count : (int), 每个connection的消费者数量 ### process.php @@ -40,9 +39,10 @@ return config('plugin.workbunny.webman-coroutine.app.enable', false) ? [ ### 默认驱动支持 -- swow -- swoole -- ripple +- [revolt/PHP-fiber](https://github.com/revoltphp/event-loop) +- [swow](https://github.com/swow/swow) +- [swoole](https://github.com/swoole/swoole-src) +- [ripple](https://github.com/cloudtay/ripple) ### swow @@ -80,6 +80,17 @@ return config('plugin.workbunny.webman-coroutine.app.enable', false) ? [ > 注:该环境协程依赖`revolt`,并没有自动`hook`系统的阻塞函数,但支持所有支持`revolt`的插件 +### revolt + +1. 使用`composer require revolt/event-loop`安装 revolt 驱动插件 + - 依赖 PHP >= 8.1 + - 依赖 workerman 5.x + - 建议安装 event/uv 拓展提高性能 +2. 修改`config/server.php`中`'event_loop' => \Workbunny\WebmanCoroutine\event_loop(Factory::REVOLT_FIBER)`自动判断 +3. 使用`php webman start` 或 `php start.php start`启动 +4. +> 注:该环境协程依赖`revolt`,并没有自动`hook`系统的阻塞函数,但支持所有支持`revolt`的插件 + ## 开发 ### 协程web服务 diff --git a/docs/doc/workerman.md b/docs/doc/workerman.md index 0cb4dd0..76daf2f 100644 --- a/docs/doc/workerman.md +++ b/docs/doc/workerman.md @@ -6,15 +6,16 @@ ### 默认驱动支持 -- swow -- swoole -- ripple +- [revolt/PHP-fiber](https://github.com/revoltphp/event-loop) +- [swow](https://github.com/swow/swow) +- [swoole](https://github.com/swoole/swoole-src) +- [ripple](https://github.com/cloudtay/ripple) ### swow 1. 使用`./vendor/bin/swow-builder`安装`swow`拓展 - 注意请关闭`swoole`环境 - - 请勿将`swow`加入`php.ini`配置文件 + - 请勿将`swow`加入`php.ini`配置文件,建议使用`-d extension=swow`加载 2. 修改启动文件中的`\Workerman\Worker::$eventLoopClass = \Workbunny\WebmanCoroutine\event_loop()`,`event_loop()`函数会根据当前环境自行判断当前的 workerman 版本,自动选择合适的事件驱动 - 当开启`swow`拓展时,`workerman 4.x`下使用`SwowEvent`事件驱动 - 当开启`swow`拓展时,`workerman 5.x`下使用`workerman`自带的`Swow`事件驱动 @@ -26,7 +27,7 @@ 1. 使用`pecl install swoole` 或者 源码编译安装稳定版 swoole 拓展 - 请注意关闭`swow`环境 - - 请勿将`swoole`加入`php.ini`配置文件 + - 请勿将`swoole`加入`php.ini`配置文件,建议使用`-d extension=swoole`加载 2. 修改启动文件中的`\Workerman\Worker::$eventLoopClass = \Workbunny\WebmanCoroutine\event_loop()`,`event_loop()`函数会根据当前环境自行判断当前的 workerman 版本,自动选择合适的事件驱动 - 当开启 swoole 拓展时,workerman 4.x 下使用 SwooleEvent 事件驱动 - 当开启 swoole 拓展时,workerman 5.x 下使用 workerman 自带的 Swoole 事件驱动 @@ -43,6 +44,16 @@ > 注:该环境协程依赖`revolt`,并没有自动`hook`系统的阻塞函数,但支持所有支持`revolt`的插件 +### revolt + +1. 使用`composer require revolt/event-loop`安装 revolt 驱动插件 + - 依赖 PHP >= 8.1 + - 依赖 workerman 5.x + - 建议安装 event/uv 拓展提高性能 +2. 修改启动文件中的`\Workerman\Worker::$eventLoopClass = \Workbunny\WebmanCoroutine\event_loop(Factory::REVOLT_FIBER)`自动判断 + +> 注:该环境协程依赖`revolt`,并没有自动`hook`系统的阻塞函数,但支持所有支持`revolt`的插件 + ## 开发 ### Utils 协程工具 diff --git a/docs/files/src-exceptions-poolexception.html b/docs/files/src-exceptions-poolexception.html new file mode 100644 index 0000000..0e8d0d6 --- /dev/null +++ b/docs/files/src-exceptions-poolexception.html @@ -0,0 +1,299 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
                +

                Documentation

                + + + + + +
                + +
                +
                + + + + +
                +
                +
                  +
                + +
                +

                PoolException.php

                + + + + + +
                + Tags + + +
                +
                +
                + author +
                +
                + +

                workbunny/Chaz6chez

                +
                + +
                +
                + email +
                +
                + +

                chaz6chez1993@outlook.com

                +
                + +
                +
                + + + + + +

                + Table of Contents + + +

                + + + + +

                + Classes + + +

                +
                +
                PoolException
                + + + + + + + + + + + + + +
                +
                +
                +
                +
                
                +        
                + +
                +
                + + + +
                +
                +
                + +
                + On this page + +
                  +
                • Table Of Contents
                • +
                • + +
                • + + +
                +
                + +
                +
                +
                +
                +
                +

                Search results

                + +
                +
                +
                  +
                  +
                  +
                  +
                  + + +
                  + + + + + + + + diff --git a/docs/files/src-handlers-handlermethods.html b/docs/files/src-handlers-handlermethods.html new file mode 100644 index 0000000..a259c44 --- /dev/null +++ b/docs/files/src-handlers-handlermethods.html @@ -0,0 +1,274 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
                  +

                  Documentation

                  + + + + + +
                  + +
                  +
                  + + + + +
                  +
                  +
                    +
                  + +
                  +

                  HandlerMethods.php

                  + + + + + + + + + + +

                  + Table of Contents + + +

                  + + + + + +

                  + Traits + + +

                  +
                  +
                  HandlerMethods
                  + + + + + + + + + + + + +
                  +
                  +
                  +
                  +
                  
                  +        
                  + +
                  +
                  + + + +
                  +
                  +
                  + +
                  + On this page + +
                    +
                  • Table Of Contents
                  • +
                  • + +
                  • + + +
                  +
                  + +
                  +
                  +
                  +
                  +
                  +

                  Search results

                  + +
                  +
                  +
                    +
                    +
                    +
                    +
                    + + +
                    + + + + + + + + diff --git a/docs/files/src-handlers-revolthandler.html b/docs/files/src-handlers-revolthandler.html new file mode 100644 index 0000000..722a915 --- /dev/null +++ b/docs/files/src-handlers-revolthandler.html @@ -0,0 +1,299 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
                    +

                    Documentation

                    + + + + + +
                    + +
                    +
                    + + + + +
                    +
                    +
                      +
                    + +
                    +

                    RevoltHandler.php

                    + + + + + +
                    + Tags + + +
                    +
                    +
                    + author +
                    +
                    + +

                    workbunny/Chaz6chez

                    +
                    + +
                    +
                    + email +
                    +
                    + +

                    chaz6chez1993@outlook.com

                    +
                    + +
                    +
                    + + + + + +

                    + Table of Contents + + +

                    + + + + +

                    + Classes + + +

                    +
                    +
                    RevoltHandler
                    基于Ripple插件的协程处理器,支持PHP-fiber
                    + + + + + + + + + + + + + +
                    +
                    +
                    +
                    +
                    
                    +        
                    + +
                    +
                    + + + +
                    +
                    +
                    + +
                    + On this page + +
                      +
                    • Table Of Contents
                    • +
                    • + +
                    • + + +
                    +
                    + +
                    +
                    +
                    +
                    +
                    +

                    Search results

                    + +
                    +
                    +
                      +
                      +
                      +
                      +
                      + + +
                      + + + + + + + + diff --git a/docs/files/src-helpers.html b/docs/files/src-helpers.html index f2cdfd0..df6d9ec 100644 --- a/docs/files/src-helpers.html +++ b/docs/files/src-helpers.html @@ -201,9 +201,9 @@

                      根据环境加载event-loop

                      @@ -248,9 +248,9 @@

                      等待回调执行返回true

                      @@ -310,9 +310,9 @@

                      判断是否composer安装了指定包

                      @@ -357,9 +357,9 @@

                      判断是否在workbunny协程环境

                      diff --git a/docs/files/src-utils-channel-handlers-revoltchannel.html b/docs/files/src-utils-channel-handlers-revoltchannel.html new file mode 100644 index 0000000..4af8509 --- /dev/null +++ b/docs/files/src-utils-channel-handlers-revoltchannel.html @@ -0,0 +1,299 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
                      +

                      Documentation

                      + + + + + +
                      + +
                      +
                      + + + + +
                      +
                      +
                        +
                      + +
                      +

                      RevoltChannel.php

                      + + + + + +
                      + Tags + + +
                      +
                      +
                      + author +
                      +
                      + +

                      workbunny/Chaz6chez

                      +
                      + +
                      +
                      + email +
                      +
                      + +

                      chaz6chez1993@outlook.com

                      +
                      + +
                      +
                      + + + + + +

                      + Table of Contents + + +

                      + + + + +

                      + Classes + + +

                      +
                      +
                      RevoltChannel
                      + + + + + + + + + + + + + +
                      +
                      +
                      +
                      +
                      
                      +        
                      + +
                      +
                      + + + +
                      +
                      +
                      + +
                      + On this page + +
                        +
                      • Table Of Contents
                      • +
                      • + +
                      • + + +
                      +
                      + +
                      +
                      +
                      +
                      +
                      +

                      Search results

                      + +
                      +
                      +
                        +
                        +
                        +
                        +
                        + + +
                        + + + + + + + + diff --git a/docs/files/src-utils-coroutine-handlers-revoltcoroutine.html b/docs/files/src-utils-coroutine-handlers-revoltcoroutine.html new file mode 100644 index 0000000..0c21e0b --- /dev/null +++ b/docs/files/src-utils-coroutine-handlers-revoltcoroutine.html @@ -0,0 +1,299 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
                        +

                        Documentation

                        + + + + + +
                        + +
                        +
                        + + + + +
                        +
                        +
                          +
                        + +
                        +

                        RevoltCoroutine.php

                        + + + + + +
                        + Tags + + +
                        +
                        +
                        + author +
                        +
                        + +

                        workbunny/Chaz6chez

                        +
                        + +
                        +
                        + email +
                        +
                        + +

                        chaz6chez1993@outlook.com

                        +
                        + +
                        +
                        + + + + + +

                        + Table of Contents + + +

                        + + + + +

                        + Classes + + +

                        +
                        +
                        RevoltCoroutine
                        + + + + + + + + + + + + + +
                        +
                        +
                        +
                        +
                        
                        +        
                        + +
                        +
                        + + + +
                        +
                        +
                        + +
                        + On this page + +
                          +
                        • Table Of Contents
                        • +
                        • + +
                        • + + +
                        +
                        + +
                        +
                        +
                        +
                        +
                        +

                        Search results

                        + +
                        +
                        +
                          +
                          +
                          +
                          +
                          + + +
                          + + + + + + + + diff --git a/docs/files/src-utils-pool-pool.html b/docs/files/src-utils-pool-pool.html new file mode 100644 index 0000000..4ec8d68 --- /dev/null +++ b/docs/files/src-utils-pool-pool.html @@ -0,0 +1,299 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
                          +

                          Documentation

                          + + + + + +
                          + +
                          +
                          + + + + +
                          +
                          +
                            +
                          + +
                          +

                          Pool.php

                          + + + + + +
                          + Tags + + +
                          +
                          +
                          + author +
                          +
                          + +

                          workbunny/Chaz6chez

                          +
                          + +
                          +
                          + email +
                          +
                          + +

                          chaz6chez1993@outlook.com

                          +
                          + +
                          +
                          + + + + + +

                          + Table of Contents + + +

                          + + + + +

                          + Classes + + +

                          +
                          +
                          Pool
                          + + + + + + + + + + + + + +
                          +
                          +
                          +
                          +
                          
                          +        
                          + +
                          +
                          + + + +
                          +
                          +
                          + +
                          + On this page + +
                            +
                          • Table Of Contents
                          • +
                          • + +
                          • + + +
                          +
                          + +
                          +
                          +
                          +
                          +
                          +

                          Search results

                          + +
                          +
                          +
                            +
                            +
                            +
                            +
                            + + +
                            + + + + + + + + diff --git a/docs/files/src-utils-waitgroup-handlers-revoltwaitgroup.html b/docs/files/src-utils-waitgroup-handlers-revoltwaitgroup.html new file mode 100644 index 0000000..70b9682 --- /dev/null +++ b/docs/files/src-utils-waitgroup-handlers-revoltwaitgroup.html @@ -0,0 +1,299 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
                            +

                            Documentation

                            + + + + + +
                            + +
                            +
                            + + + + +
                            +
                            +
                              +
                            + +
                            +

                            RevoltWaitGroup.php

                            + + + + + +
                            + Tags + + +
                            +
                            +
                            + author +
                            +
                            + +

                            workbunny/Chaz6chez

                            +
                            + +
                            +
                            + email +
                            +
                            + +

                            chaz6chez1993@outlook.com

                            +
                            + +
                            +
                            + + + + + +

                            + Table of Contents + + +

                            + + + + +

                            + Classes + + +

                            +
                            +
                            RevoltWaitGroup
                            + + + + + + + + + + + + + +
                            +
                            +
                            +
                            +
                            
                            +        
                            + +
                            +
                            + + + +
                            +
                            +
                            + +
                            + On this page + +
                              +
                            • Table Of Contents
                            • +
                            • + +
                            • + + +
                            +
                            + +
                            +
                            +
                            +
                            +
                            +

                            Search results

                            + +
                            +
                            +
                              +
                              +
                              +
                              +
                              + + +
                              + + + + + + + + diff --git a/docs/files/src/CoroutineWebServer.php.txt b/docs/files/src/CoroutineWebServer.php.txt index fbf9e2e..c4a4b24 100644 --- a/docs/files/src/CoroutineWebServer.php.txt +++ b/docs/files/src/CoroutineWebServer.php.txt @@ -20,7 +20,6 @@ use Workerman\Worker; */ class CoroutineWebServer extends App { - /** * 每个连接的协程计数 * @@ -155,13 +154,16 @@ class CoroutineWebServer extends App $waitGroup->add(); // 请求消费协程 new Coroutine(function () use (&$res, $waitGroup, $params, $connectionId) { - $res = parent::onMessage(...$params); - // 计数 -- - self::$_connectionCoroutineCount[$connectionId] --; - // 尝试回收 - self::unsetConnectionCoroutineCount($connectionId); - // wg完成 - $waitGroup->done(); + try { + $res = parent::onMessage(...$params); + } finally { + // 计数 -- + self::$_connectionCoroutineCount[$connectionId]--; + // 尝试回收 + self::unsetConnectionCoroutineCount($connectionId); + // wg完成 + $waitGroup->done(); + } }); // 计数 ++ self::$_connectionCoroutineCount[$connectionId] = @@ -170,6 +172,7 @@ class CoroutineWebServer extends App : 1); // 等待 $waitGroup->wait(); + return $res; } } diff --git a/docs/files/src/Events/SwooleEvent.php.txt b/docs/files/src/Events/SwooleEvent.php.txt index 8690c59..97d5102 100644 --- a/docs/files/src/Events/SwooleEvent.php.txt +++ b/docs/files/src/Events/SwooleEvent.php.txt @@ -26,11 +26,11 @@ class SwooleEvent implements EventInterface /** @var callable[] Event listeners of signal. */ protected array $_signals = []; - /** @var int[] Timer id to timer info. */ + /** @var int[]|true[] Timer id to timer info. */ protected array $_timer = []; /** @var int 定时器id */ - protected int $_timerId = 0; + protected int $_timerId = 1; /** * @param bool $debug 测试用 @@ -60,12 +60,37 @@ class SwooleEvent implements EventInterface case EventInterface::EV_TIMER: case EventInterface::EV_TIMER_ONCE: $timerId = $this->_timerId++; - $this->_timer[$timerId] = Timer::after((int) ($fd * 1000), function () use ($timerId, $flag, $func) { - call_user_func($func); - if ($flag === EventInterface::EV_TIMER_ONCE) { - $this->del($timerId, $flag); - } - }); + if (($interval = (int) ($fd * 1000)) >= 1) { + $res = Timer::tick($interval, function () use ($timerId, $flag, $func, $args) { + call_user_func($func, ...$args); + if ($flag === EventInterface::EV_TIMER_ONCE) { + $this->del($timerId, $flag); + } + }); + } else { + $res = Coroutine::create(function () use ($fd, $timerId, $flag, $func, $args) { + while (true) { + usleep((int) ($fd * 1000 * 1000)); + if (!isset($this->_timer[$timerId])) { + return; + } + call_user_func($func, ...$args); + if ($flag === EventInterface::EV_TIMER_ONCE) { + $this->del($timerId, $flag); + + return; + } + } + }); + $res = $res !== false; + } + + if ($res === false) { + $this->_timerId--; + + return false; + } + $this->_timer[$timerId] = $res; return $timerId; case EventInterface::EV_READ: @@ -116,7 +141,7 @@ class SwooleEvent implements EventInterface case self::EV_TIMER: case self::EV_TIMER_ONCE: if ($id = $this->_timer[$fd] ?? null) { - if (Timer::clear($id)) { + if ($id === true or Timer::clear($id)) { unset($this->_timer[$fd]); return true; @@ -184,7 +209,9 @@ class SwooleEvent implements EventInterface public function clearAllTimer() { foreach ($this->_timer as $id) { - Timer::clear($id); + if (is_int($id)) { + Timer::clear($id); + } } $this->_timer = []; } diff --git a/docs/files/src/Events/SwowEvent.php.txt b/docs/files/src/Events/SwowEvent.php.txt index c42f2b4..912eb34 100644 --- a/docs/files/src/Events/SwowEvent.php.txt +++ b/docs/files/src/Events/SwowEvent.php.txt @@ -29,7 +29,7 @@ class SwowEvent implements EventInterface protected array $_timer = []; /** @var int 定时器id */ - protected int $_timerId = 0; + protected int $_timerId = 1; /** @var WaitGroup|null 阻塞 */ protected null|WaitGroup $_waitGroup = null; @@ -68,7 +68,7 @@ class SwowEvent implements EventInterface $timerId = $this->_timerId++; $this->_timer[$timerId] = Coroutine::run(function () use ($timerId, $fd, $flag, $func, $args): void { while (1) { - msleep((int) ($fd * 1000)); + usleep((int) ($fd * 1000 * 1000)); \call_user_func($func, ...$args); if ($flag === EventInterface::EV_TIMER_ONCE) { $this->del($timerId, $flag); diff --git a/docs/files/src/Exceptions/PoolException.php.txt b/docs/files/src/Exceptions/PoolException.php.txt new file mode 100644 index 0000000..3bc93a0 --- /dev/null +++ b/docs/files/src/Exceptions/PoolException.php.txt @@ -0,0 +1,12 @@ + SwowHandler::class, self::WORKERMAN_SWOOLE => SwooleWorkerman5Handler::class, self::WORKBUNNY_SWOOLE => SwooleHandler::class, - self::REVOLT_FIBER => RippleWorkerman5Handler::class, + self::REVOLT_FIBER => RevoltHandler::class, self::RIPPLE_FIBER => RippleHandler::class, + self::RIPPLE_FIBER_5 => RippleWorkerman5Handler::class, ]; /** diff --git a/docs/files/src/Handlers/DefaultHandler.php.txt b/docs/files/src/Handlers/DefaultHandler.php.txt index b211e57..8581885 100644 --- a/docs/files/src/Handlers/DefaultHandler.php.txt +++ b/docs/files/src/Handlers/DefaultHandler.php.txt @@ -7,8 +7,6 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine\Handlers; -use Closure; - /** * 默认处理器,使用workerman基础事件 */ diff --git a/docs/files/src/Handlers/HandlerMethods.php.txt b/docs/files/src/Handlers/HandlerMethods.php.txt new file mode 100644 index 0000000..f055f49 --- /dev/null +++ b/docs/files/src/Handlers/HandlerMethods.php.txt @@ -0,0 +1,22 @@ +=') and + package_installed('revolt/event-loop') and + PHP_VERSION_ID >= 81000; + } + + /** + * ripple handler无需初始化 + * + * @inheritdoc + */ + public static function initEnv(): void + { + } + + /** @inheritdoc */ + public static function waitFor(?\Closure $closure = null, float|int $timeout = -1): void + { + $time = microtime(true); + while (true) { + if ($closure and call_user_func($closure) === true) { + return; + } + if ($timeout > 0 && microtime(true) - $time >= $timeout) { + return; + } + RevoltHandler::sleep($timeout); + } + } + + /** + * @param int|float $second 单位:秒 + * @return void + */ + public static function sleep(int|float $second): void + { + $suspension = EventLoop::getSuspension(); + // 毫秒及以上 + if ($second >= 0.001) { + EventLoop::delay((float)$second, function () use ($suspension) { + $suspension->resume(); + }); + } + // 毫秒以下 + else { + $start = microtime(true); + EventLoop::defer($fuc = function () use (&$fuc, $suspension, $second, $start) { + if (microtime(true) - $start >= $second) { + $suspension->resume(); + } else { + EventLoop::defer($fuc); + } + }); + } + $suspension->suspend(); + } +} diff --git a/docs/files/src/Handlers/RippleHandler.php.txt b/docs/files/src/Handlers/RippleHandler.php.txt index c706e79..6249f56 100644 --- a/docs/files/src/Handlers/RippleHandler.php.txt +++ b/docs/files/src/Handlers/RippleHandler.php.txt @@ -7,7 +7,6 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine\Handlers; -use Workerman\Worker; use function Workbunny\WebmanCoroutine\package_installed; /** @@ -15,21 +14,15 @@ use function Workbunny\WebmanCoroutine\package_installed; */ class RippleHandler implements HandlerInterface { + use HandlerMethods; /** @inheritdoc */ public static function isAvailable(): bool { - return version_compare(static::_getWorkerVersion(), '5.0.0', '<') and package_installed('cclilshy/p-ripple-drive'); - } - - /** - * 为了测试可以mock - * - * @return string - */ - protected static function _getWorkerVersion(): string - { - return Worker::VERSION; + return + version_compare(static::_getWorkerVersion(), '5.0.0', '<') and + package_installed('cclilshy/p-ripple-drive') and + PHP_VERSION_ID >= 81000; } /** diff --git a/docs/files/src/Handlers/RippleWorkerman5Handler.php.txt b/docs/files/src/Handlers/RippleWorkerman5Handler.php.txt index 4a834e1..9a47f99 100644 --- a/docs/files/src/Handlers/RippleWorkerman5Handler.php.txt +++ b/docs/files/src/Handlers/RippleWorkerman5Handler.php.txt @@ -7,7 +7,6 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine\Handlers; -use Workerman\Worker; use function Workbunny\WebmanCoroutine\package_installed; /** @@ -15,21 +14,15 @@ use function Workbunny\WebmanCoroutine\package_installed; */ class RippleWorkerman5Handler implements HandlerInterface { + use HandlerMethods; /** @inheritdoc */ public static function isAvailable(): bool { - return version_compare(static::_getWorkerVersion(), '5.0.0', '>=') and package_installed('cclilshy/p-ripple-drive'); - } - - /** - * 为了测试可以mock - * - * @return string - */ - protected static function _getWorkerVersion(): string - { - return Worker::VERSION; + return + version_compare(static::_getWorkerVersion(), '5.0.0', '>=') and + package_installed('cclilshy/p-ripple-drive') and + PHP_VERSION_ID >= 81000; } /** diff --git a/docs/files/src/Handlers/SwooleHandler.php.txt b/docs/files/src/Handlers/SwooleHandler.php.txt index b9e3fc7..ce8f42e 100644 --- a/docs/files/src/Handlers/SwooleHandler.php.txt +++ b/docs/files/src/Handlers/SwooleHandler.php.txt @@ -8,17 +8,18 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine\Handlers; use Swoole\Runtime; -use Workerman\Worker; /** * 基于swoole实现的协程处理器 */ class SwooleHandler implements HandlerInterface { + use HandlerMethods; + /** @inheritdoc */ public static function isAvailable(): bool { - return version_compare(Worker::VERSION, '5.0.0', '<') and extension_loaded('swoole'); + return version_compare(static::_getWorkerVersion(), '5.0.0', '<') and extension_loaded('swoole'); } /** @inheritdoc */ @@ -38,7 +39,7 @@ class SwooleHandler implements HandlerInterface if ($timeout > 0 && microtime(true) - $time >= $timeout) { return; } - usleep(max((int)($timeout * 1000 * 1000), 0)); + usleep(max((int) ($timeout * 1000 * 1000), 0)); } } } diff --git a/docs/files/src/Handlers/SwooleWorkerman5Handler.php.txt b/docs/files/src/Handlers/SwooleWorkerman5Handler.php.txt index 67a3a41..8d9489f 100644 --- a/docs/files/src/Handlers/SwooleWorkerman5Handler.php.txt +++ b/docs/files/src/Handlers/SwooleWorkerman5Handler.php.txt @@ -7,16 +7,16 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine\Handlers; -use Workerman\Worker; - /** * 基于swoole实现的Workerman5.x版本协程处理器 */ class SwooleWorkerman5Handler extends SwooleHandler { + use HandlerMethods; + /** @inheritdoc */ public static function isAvailable(): bool { - return version_compare(Worker::VERSION, '5.0.0', '>=') and extension_loaded('swoole'); + return version_compare(static::_getWorkerVersion(), '5.0.0', '>=') and extension_loaded('swoole'); } } diff --git a/docs/files/src/Handlers/SwowHandler.php.txt b/docs/files/src/Handlers/SwowHandler.php.txt index 0e28c01..cb157e0 100644 --- a/docs/files/src/Handlers/SwowHandler.php.txt +++ b/docs/files/src/Handlers/SwowHandler.php.txt @@ -7,18 +7,17 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine\Handlers; -use Workerman\Worker; - /** * 基于swow实现的协程处理器 */ class SwowHandler implements HandlerInterface { + use HandlerMethods; /** @inheritdoc */ public static function isAvailable(): bool { - return !version_compare(Worker::VERSION, '5.0.0', '>=') and extension_loaded('swow'); + return !version_compare(static::_getWorkerVersion(), '5.0.0', '>=') and extension_loaded('swow'); } /** @@ -41,7 +40,7 @@ class SwowHandler implements HandlerInterface if ($timeout > 0 && microtime(true) - $time >= $timeout) { return; } - usleep(max((int)($timeout * 1000 * 1000), 0)); + usleep(max((int) ($timeout * 1000 * 1000), 0)); } } } diff --git a/docs/files/src/Handlers/SwowWorkerman5Handler.php.txt b/docs/files/src/Handlers/SwowWorkerman5Handler.php.txt index b5ca2d6..70e9795 100644 --- a/docs/files/src/Handlers/SwowWorkerman5Handler.php.txt +++ b/docs/files/src/Handlers/SwowWorkerman5Handler.php.txt @@ -7,16 +7,16 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine\Handlers; -use Workerman\Worker; - /** * 基于swow实现的Workerman5.X的协程处理器 */ class SwowWorkerman5Handler extends SwowHandler { + use HandlerMethods; + /** @inheritdoc */ public static function isAvailable(): bool { - return version_compare(Worker::VERSION, '5.0.0', '>=') and extension_loaded('swow'); + return version_compare(static::_getWorkerVersion(), '5.0.0', '>=') and extension_loaded('swow'); } } diff --git a/docs/files/src/Utils/Channel/Channel.php.txt b/docs/files/src/Utils/Channel/Channel.php.txt index edebbd7..11aa773 100644 --- a/docs/files/src/Utils/Channel/Channel.php.txt +++ b/docs/files/src/Utils/Channel/Channel.php.txt @@ -10,6 +10,7 @@ namespace Workbunny\WebmanCoroutine\Utils\Channel; use Workbunny\WebmanCoroutine\Factory; use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\ChannelInterface; use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\DefaultChannel; +use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\RevoltChannel; use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\RippleChannel; use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\SwooleChannel; use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\SwowChannel; @@ -40,8 +41,9 @@ class Channel Factory::WORKBUNNY_SWOW => SwowChannel::class, Factory::WORKERMAN_SWOOLE => SwooleChannel::class, Factory::WORKBUNNY_SWOOLE => SwooleChannel::class, - Factory::REVOLT_FIBER => RippleChannel::class, + Factory::REVOLT_FIBER => RevoltChannel::class, Factory::RIPPLE_FIBER => RippleChannel::class, + Factory::RIPPLE_FIBER_5 => RippleChannel::class, ]; /** @@ -84,6 +86,7 @@ class Channel if (!method_exists($this->_interface, $name)) { throw new \BadMethodCallException("Method $name not exists. "); } + return $this->_interface->$name(...$arguments); } -} \ No newline at end of file +} diff --git a/docs/files/src/Utils/Channel/Handlers/ChannelInterface.php.txt b/docs/files/src/Utils/Channel/Handlers/ChannelInterface.php.txt index be4389d..6242bf2 100644 --- a/docs/files/src/Utils/Channel/Handlers/ChannelInterface.php.txt +++ b/docs/files/src/Utils/Channel/Handlers/ChannelInterface.php.txt @@ -9,7 +9,6 @@ namespace Workbunny\WebmanCoroutine\Utils\Channel\Handlers; interface ChannelInterface { - /** * 初始化通道 * @@ -66,4 +65,4 @@ interface ChannelInterface * @return void */ public function close(): void; -} \ No newline at end of file +} diff --git a/docs/files/src/Utils/Channel/Handlers/DefaultChannel.php.txt b/docs/files/src/Utils/Channel/Handlers/DefaultChannel.php.txt index 063c5ff..aae09f1 100644 --- a/docs/files/src/Utils/Channel/Handlers/DefaultChannel.php.txt +++ b/docs/files/src/Utils/Channel/Handlers/DefaultChannel.php.txt @@ -9,11 +9,10 @@ namespace Workbunny\WebmanCoroutine\Utils\Channel\Handlers; class DefaultChannel implements ChannelInterface { - - /** @var \SplQueue|null */ + /** @var \SplQueue|null */ protected ?\SplQueue $_queue; - /** @var int */ + /** @var int */ protected int $_capacity; /** @inheritdoc */ @@ -26,7 +25,6 @@ class DefaultChannel implements ChannelInterface /** @inheritdoc */ public function __destruct() { - $this->close(); } public function pop(int|float $timeout = -1): mixed @@ -38,6 +36,7 @@ class DefaultChannel implements ChannelInterface public function push(mixed $data, int|float $timeout = -1): bool { $this->_queue->enqueue($data); + return true; } diff --git a/docs/files/src/Utils/Channel/Handlers/RevoltChannel.php.txt b/docs/files/src/Utils/Channel/Handlers/RevoltChannel.php.txt new file mode 100644 index 0000000..689431f --- /dev/null +++ b/docs/files/src/Utils/Channel/Handlers/RevoltChannel.php.txt @@ -0,0 +1,91 @@ +_queue = new \SplQueue(); + $this->_capacity = $capacity; + } + + /** @inheritdoc */ + public function __destruct() + { + } + + /** @inheritdoc */ + public function pop(int|float $timeout = -1): mixed + { + $time = microtime(true); + while (1) { + if (!$this->isEmpty()) { + return $this->_queue->dequeue(); + } else { + // timeout + if ($timeout > 0 and microtime(true) - $time >= $timeout) { + return false; + } + RevoltHandler::sleep(max($timeout, 0)); + } + } + } + + /** @inheritdoc */ + public function push(mixed $data, int|float $timeout = -1): bool + { + $time = microtime(true); + while (1) { + if (!$this->isFull()) { + $this->_queue->enqueue($data); + + return true; + } else { + // timeout + if ($timeout > 0 and microtime(true) - $time >= $timeout) { + return false; + } + RevoltHandler::sleep(max($timeout, 0)); + } + } + } + + /** @inheritdoc */ + public function isEmpty(): bool + { + return $this->_queue->isEmpty(); + } + + /** @inheritdoc */ + public function isFull(): bool + { + return !($this->capacity() < 0) && $this->capacity() <= $this->_queue->count(); + } + + /** @inheritdoc */ + public function close(): void + { + $this->_queue = new \SplQueue(); + } + + /** @inheritdoc */ + public function capacity(): int + { + return $this->_capacity; + } +} diff --git a/docs/files/src/Utils/Channel/Handlers/RippleChannel.php.txt b/docs/files/src/Utils/Channel/Handlers/RippleChannel.php.txt index 6a69d48..75938dc 100644 --- a/docs/files/src/Utils/Channel/Handlers/RippleChannel.php.txt +++ b/docs/files/src/Utils/Channel/Handlers/RippleChannel.php.txt @@ -9,11 +9,10 @@ namespace Workbunny\WebmanCoroutine\Utils\Channel\Handlers; class RippleChannel implements ChannelInterface { - - /** @var \SplQueue */ + /** @var \SplQueue */ protected \SplQueue $_queue; - /** @var int */ + /** @var int */ protected int $_capacity; /** @inheritdoc */ @@ -26,7 +25,6 @@ class RippleChannel implements ChannelInterface /** @inheritdoc */ public function __destruct() { - $this->close(); } /** @@ -62,6 +60,7 @@ class RippleChannel implements ChannelInterface while (1) { if (!$this->isFull()) { $this->_queue->enqueue($data); + return true; } else { // timeout diff --git a/docs/files/src/Utils/Channel/Handlers/SwooleChannel.php.txt b/docs/files/src/Utils/Channel/Handlers/SwooleChannel.php.txt index 69d5cd2..404d824 100644 --- a/docs/files/src/Utils/Channel/Handlers/SwooleChannel.php.txt +++ b/docs/files/src/Utils/Channel/Handlers/SwooleChannel.php.txt @@ -11,8 +11,7 @@ use Swoole\Coroutine\Channel; class SwooleChannel implements ChannelInterface { - - /** @var Channel */ + /** @var Channel */ protected Channel $_channel; /** @inheritdoc */ @@ -30,13 +29,13 @@ class SwooleChannel implements ChannelInterface /** @inheritdoc */ public function pop(int|float $timeout = -1): mixed { - return $this->_channel->pop((float)$timeout); + return $this->_channel->pop((float) $timeout); } /** @inheritdoc */ public function push(mixed $data, int|float $timeout = -1): mixed { - return $this->_channel->push($data, (float)$timeout); + return $this->_channel->push($data, (float) $timeout); } /** @inheritdoc */ diff --git a/docs/files/src/Utils/Channel/Handlers/SwowChannel.php.txt b/docs/files/src/Utils/Channel/Handlers/SwowChannel.php.txt index 6f8fbfc..5df6541 100644 --- a/docs/files/src/Utils/Channel/Handlers/SwowChannel.php.txt +++ b/docs/files/src/Utils/Channel/Handlers/SwowChannel.php.txt @@ -11,8 +11,7 @@ use Swow\Channel; class SwowChannel implements ChannelInterface { - - /** @var Channel */ + /** @var Channel */ protected Channel $_channel; /** @inheritdoc */ @@ -69,6 +68,6 @@ class SwowChannel implements ChannelInterface */ protected function _second2microsecond(int|float $timeout): int { - return $timeout > 0 ? (int)($timeout * 1000 * 1000) : -1; + return $timeout > 0 ? (int) ($timeout * 1000 * 1000) : -1; } } diff --git a/docs/files/src/Utils/Coroutine/Coroutine.php.txt b/docs/files/src/Utils/Coroutine/Coroutine.php.txt index 6c4fe55..7ed418c 100644 --- a/docs/files/src/Utils/Coroutine/Coroutine.php.txt +++ b/docs/files/src/Utils/Coroutine/Coroutine.php.txt @@ -11,6 +11,7 @@ use Closure; use Workbunny\WebmanCoroutine\Factory; use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\CoroutineInterface; use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\DefaultCoroutine; +use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\RevoltCoroutine; use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\RippleCoroutine; use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\SwooleCoroutine; use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\SwowCoroutine; @@ -18,6 +19,7 @@ use Workbunny\WebmanCoroutine\Utils\RegisterMethods; /** * @method mixed origin() + * @method string|int id() */ class Coroutine { @@ -36,21 +38,25 @@ class Coroutine Factory::WORKBUNNY_SWOW => SwowCoroutine::class, Factory::WORKERMAN_SWOOLE => SwooleCoroutine::class, Factory::WORKBUNNY_SWOOLE => SwooleCoroutine::class, - Factory::REVOLT_FIBER => RippleCoroutine::class, + Factory::REVOLT_FIBER => RevoltCoroutine::class, Factory::RIPPLE_FIBER => RippleCoroutine::class, + Factory::RIPPLE_FIBER_5 => RippleCoroutine::class, ]; /** * 构造方法 - */ - /** + * * @param Closure $func + * @link CoroutineInterface::__construct */ public function __construct(Closure $func) { $this->_interface = new (self::$_handlers[Factory::getCurrentEventLoop()] ?? DefaultCoroutine::class)($func); } + /** + * 析构 + */ public function __destruct() { $this->_interface = null; @@ -80,6 +86,7 @@ class Coroutine if (!method_exists($this->_interface, $name)) { throw new \BadMethodCallException("Method $name not exists. "); } + return $this->_interface->$name(...$arguments); } -} \ No newline at end of file +} diff --git a/docs/files/src/Utils/Coroutine/Handlers/CoroutineInterface.php.txt b/docs/files/src/Utils/Coroutine/Handlers/CoroutineInterface.php.txt index d71520d..e73b82b 100644 --- a/docs/files/src/Utils/Coroutine/Handlers/CoroutineInterface.php.txt +++ b/docs/files/src/Utils/Coroutine/Handlers/CoroutineInterface.php.txt @@ -11,6 +11,8 @@ interface CoroutineInterface { /** * 创建协程 + * + * @param \Closure $func = function (mixed $coroutineId) {} */ public function __construct(\Closure $func); @@ -29,7 +31,7 @@ interface CoroutineInterface /** * 获取协程id * - * @return string|int + * @return string|int|null */ - public function id(): string|int; -} \ No newline at end of file + public function id(): string|int|null; +} diff --git a/docs/files/src/Utils/Coroutine/Handlers/DefaultCoroutine.php.txt b/docs/files/src/Utils/Coroutine/Handlers/DefaultCoroutine.php.txt index 0f9db3f..ee38ba1 100644 --- a/docs/files/src/Utils/Coroutine/Handlers/DefaultCoroutine.php.txt +++ b/docs/files/src/Utils/Coroutine/Handlers/DefaultCoroutine.php.txt @@ -9,17 +9,16 @@ namespace Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers; class DefaultCoroutine implements CoroutineInterface { - /** - * @var string + * @var string|null */ - protected string $id; + protected ?string $id = null; /** @inheritdoc */ public function __construct(\Closure $func) { - call_user_func($func); - $this->id = spl_object_hash($func); + call_user_func($func, $this->id = spl_object_hash($func)); + $this->id = null; } /** @inheritdoc */ @@ -34,7 +33,7 @@ class DefaultCoroutine implements CoroutineInterface } /** @inheritdoc */ - public function id(): string + public function id(): ?string { return $this->id; } diff --git a/docs/files/src/Utils/Coroutine/Handlers/RevoltCoroutine.php.txt b/docs/files/src/Utils/Coroutine/Handlers/RevoltCoroutine.php.txt new file mode 100644 index 0000000..9645e2c --- /dev/null +++ b/docs/files/src/Utils/Coroutine/Handlers/RevoltCoroutine.php.txt @@ -0,0 +1,56 @@ +_suspension = EventLoop::getSuspension(); + // 将fiber恢复到队列中 + EventLoop::queue(function () { + $this->_suspension->resume(); + }); + // 当前fiber挂起 + $this->_suspension->suspend(); + try { + // 等待恢复后执行逻辑 + call_user_func($func); + } finally { + $this->_suspension = null; + } + } + + /** @inheritdoc */ + public function __destruct() + { + $this->_suspension = null; + } + + /** @inheritdoc */ + public function origin(): ?EventLoop\Suspension + { + return $this->_suspension; + } + + /** @inheritdoc */ + public function id(): ?string + { + return $this->_suspension ? spl_object_hash($this->_suspension) : null; + } +} diff --git a/docs/files/src/Utils/Coroutine/Handlers/RippleCoroutine.php.txt b/docs/files/src/Utils/Coroutine/Handlers/RippleCoroutine.php.txt index 3df9904..5137660 100644 --- a/docs/files/src/Utils/Coroutine/Handlers/RippleCoroutine.php.txt +++ b/docs/files/src/Utils/Coroutine/Handlers/RippleCoroutine.php.txt @@ -7,32 +7,30 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers; -use Psc\Core\Coroutine\Promise; use function Co\async; +use Psc\Core\Coroutine\Promise; + class RippleCoroutine implements CoroutineInterface { /** * @var null|Promise */ - protected ?Promise $_promise; - - /** - * @var string - */ - protected string $_id; + protected ?Promise $_promise = null; /** @inheritdoc * @param \Closure $func */ public function __construct(\Closure $func) { - $this->_promise = $this->_async(function () use (&$promise, $func) { - call_user_func($func); - // 移除协程id及promise - $this->_promise = null; + $this->_promise = $promise = $this->_async(function () use (&$promise, $func) { + try { + call_user_func($func, spl_object_hash($this->_promise)); + } finally { + // 移除协程promise + $this->_promise = null; + } }); - $this->_id = spl_object_hash($this->_promise); } /** @inheritdoc */ @@ -44,14 +42,13 @@ class RippleCoroutine implements CoroutineInterface /** @inheritdoc */ public function origin(): ?Promise { - return $this->_promise; } /** @inheritdoc */ - public function id(): string + public function id(): ?string { - return $this->_id; + return $this->_promise ? spl_object_hash($this->_promise) : null; } /** diff --git a/docs/files/src/Utils/Coroutine/Handlers/SwooleCoroutine.php.txt b/docs/files/src/Utils/Coroutine/Handlers/SwooleCoroutine.php.txt index 4d9c3d8..1aa77ba 100644 --- a/docs/files/src/Utils/Coroutine/Handlers/SwooleCoroutine.php.txt +++ b/docs/files/src/Utils/Coroutine/Handlers/SwooleCoroutine.php.txt @@ -14,7 +14,7 @@ class SwooleCoroutine implements CoroutineInterface /** * @var int|null */ - protected ?int $_id; + protected ?int $_id = null; /** @inheritdoc * @param \Closure $func @@ -22,8 +22,14 @@ class SwooleCoroutine implements CoroutineInterface public function __construct(\Closure $func) { while (1) { - if ($res = Coroutine::create($func)) { - $this->_id = $res; + if ($id = Coroutine::create(function () use ($func) { + try { + call_user_func($func, $this->_id); + } finally { + $this->_id = null; + } + })) { + $this->_id = $id; break; } } @@ -42,7 +48,7 @@ class SwooleCoroutine implements CoroutineInterface } /** @inheritdoc */ - public function id(): int + public function id(): ?int { return $this->_id; } diff --git a/docs/files/src/Utils/Coroutine/Handlers/SwowCoroutine.php.txt b/docs/files/src/Utils/Coroutine/Handlers/SwowCoroutine.php.txt index af235e8..b9bb7f4 100644 --- a/docs/files/src/Utils/Coroutine/Handlers/SwowCoroutine.php.txt +++ b/docs/files/src/Utils/Coroutine/Handlers/SwowCoroutine.php.txt @@ -14,20 +14,18 @@ class SwowCoroutine implements CoroutineInterface /** * @var null|Coroutine */ - protected ?Coroutine $_coroutine; + protected ?Coroutine $_coroutine = null; - /** - * @var int - */ - protected int $_id; - - /** @inheritdoc - * @param \Closure $func - */ + /** @inheritDoc */ public function __construct(\Closure $func) { - $this->_coroutine = Coroutine::run($func); - $this->_id = $this->_coroutine->getId(); + $this->_coroutine = Coroutine::run(function () use ($func) { + try { + call_user_func($func, $this->_coroutine->getId()); + } finally { + $this->_coroutine = null; + } + }); } /** @inheritdoc */ @@ -43,8 +41,8 @@ class SwowCoroutine implements CoroutineInterface } /** @inheritdoc */ - public function id(): int + public function id(): ?int { - return $this->_id; + return $this->_coroutine?->getId(); } } diff --git a/docs/files/src/Utils/Pool/Pool.php.txt b/docs/files/src/Utils/Pool/Pool.php.txt new file mode 100644 index 0000000..2161d96 --- /dev/null +++ b/docs/files/src/Utils/Pool/Pool.php.txt @@ -0,0 +1,277 @@ + $pool) { + // Pool + if ($pool instanceof Pool) { + $pool->setForce($force); + unset(self::$pools[$name][$in]); + continue; + } + /** + * 非Pool则为数组 + * @var int $i + * @var Pool $p + */ + foreach ($pool as $i => $p) { + $p->setForce($force); + unset(self::$pools[$name][$i]); + } + } + } + + } + + /** + * 获取 + * + * @param string $name + * @param int|null $index + * @return Pool|Pool[]|null + */ + public static function get(string $name, ?int $index): Pool|array|null + { + $pools = self::$pools[$name] ?? []; + return $index !== null ? ($pools[$index] ?? null) : $pools; + } + + /** + * 获取空闲池 + * + * @param string $name + * @return Pool|null + */ + public static function idle(string $name): Pool|null + { + $pools = self::get($name, null); + // 总是按顺序优先获取空闲 + foreach ($pools as $pool) { + if ($pool->isIdle()) { + return $pool; + } + } + return null; + } + + /** + * 等待空闲并执行 + * + * @param string $name 池区域 + * @param \Closure $closure 被执行函数 = function (Pool $pool) {} + * @param int $timeout 超时时间 + * @return mixed + */ + public static function waitForIdle(string $name, \Closure $closure, int $timeout = -1): mixed + { + $pool = null; + wait_for(function () use (&$pool, $name) { + $pool = self::idle($name); + return $pool !== null; + }, $timeout); + return call_user_func($closure, $pool); + } + + /** + * 构造 + * + * @param string $name + * @param int $index 索引 + * @param object|array|resource|mixed $element + */ + public function __construct(string $name, int $index, mixed $element) + { + if (static::get($name, $index)) { + throw new PoolException("Pool $name#$index already exists. ", -2); + } + $this->_name = $name; + $this->_index = $index; + $this->setForce(false); + $this->setIdle(true); + $this->_element = match (true) { + is_object($element), is_array($element) => clone $element, + is_callable($element) => call_user_func($element), + default => $element, + }; + } + + /** + * 析构等待销毁 + */ + public function __destruct() + { + if (!$this->isForce()) { + $this->wait(); + } + } + + /** + * 获取所在区域名称 + * + * @return string + */ + public function getName(): string + { + return $this->_name; + } + + /** + * 所在区域的索引 + * + * @return int + */ + public function getIndex(): int + { + return $this->_index; + } + + /** + * 获取元素 + * + * @return resource|object|array|mixed + */ + public function getElement(): mixed + { + return $this->_element; + } + + /** + * 是否闲置 + * + * @return bool + */ + public function isIdle(): bool + { + return $this->_idle; + } + + /** + * 设置状态 + * + * @param bool $idle + * @return void + */ + public function setIdle(bool $idle): void + { + $this->_idle = $idle; + } + + /** + * 是否强制回收 + * + * @return bool + */ + public function isForce(): bool + { + return $this->_force; + } + + /** + * 设置强制回收 + * + * @param bool $force + * @return void + */ + public function setForce(bool $force): void + { + $this->_force = $force; + } + + /** + * 等待至闲置 + * + * @param \Closure|null $closure + * @return void + */ + public function wait(?\Closure $closure = null): void + { + wait_for(function () { + return $this->isIdle(); + }); + if ($closure) { + call_user_func($closure, $this); + } + } +} \ No newline at end of file diff --git a/docs/files/src/Utils/RegisterMethods.php.txt b/docs/files/src/Utils/RegisterMethods.php.txt index 5c1f466..f7f290e 100644 --- a/docs/files/src/Utils/RegisterMethods.php.txt +++ b/docs/files/src/Utils/RegisterMethods.php.txt @@ -11,7 +11,6 @@ use InvalidArgumentException; trait RegisterMethods { - /** * 注册 * @@ -24,10 +23,13 @@ trait RegisterMethods if (!self::$_handlers[$key] ?? null) { if ($value = self::registerVerify($value)) { self::$_handlers[$key] = $value; + return true; } + return false; } + return null; } @@ -68,7 +70,6 @@ trait RegisterMethods */ abstract public static function unregisterExecute(string $key): bool; - /** * 获取指定handler 或 获取所有 * @@ -78,4 +79,4 @@ trait RegisterMethods { return $key === null ? self::$_handlers : self::$_handlers[$key] ?? null; } -} \ No newline at end of file +} diff --git a/docs/files/src/Utils/WaitGroup/Handlers/RevoltWaitGroup.php.txt b/docs/files/src/Utils/WaitGroup/Handlers/RevoltWaitGroup.php.txt new file mode 100644 index 0000000..65f3b87 --- /dev/null +++ b/docs/files/src/Utils/WaitGroup/Handlers/RevoltWaitGroup.php.txt @@ -0,0 +1,75 @@ +_count = 0; + } + + /** @inheritdoc */ + public function __destruct() + { + try { + $count = $this->count(); + if ($count > 0) { + foreach (range(1, $count) as $ignored) { + $this->done(); + } + } + } catch (\Throwable) { + } finally { + $this->_count = 0; + } + } + + /** @inheritdoc */ + public function add(int $delta = 1): bool + { + $this->_count++; + + return true; + } + + /** @inheritdoc */ + public function done(): bool + { + $this->_count--; + + return true; + } + + /** @inheritdoc */ + public function count(): int + { + return $this->_count; + } + + /** @inheritdoc */ + public function wait(int|float $timeout = -1): void + { + $time = microtime(true); + while (1) { + if ($timeout > 0 and microtime(true) - $time >= $timeout) { + return; + } + if ($this->_count <= 0) { + return; + } + RevoltHandler::sleep(max($timeout, 0)); + } + } +} diff --git a/docs/files/src/Utils/WaitGroup/Handlers/RippleWaitGroup.php.txt b/docs/files/src/Utils/WaitGroup/Handlers/RippleWaitGroup.php.txt index 41775ab..2fd13f4 100644 --- a/docs/files/src/Utils/WaitGroup/Handlers/RippleWaitGroup.php.txt +++ b/docs/files/src/Utils/WaitGroup/Handlers/RippleWaitGroup.php.txt @@ -9,7 +9,7 @@ namespace Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers; class RippleWaitGroup implements WaitGroupInterface { - /** @var int */ + /** @var int */ protected int $_count; /** @inheritdoc */ @@ -28,23 +28,25 @@ class RippleWaitGroup implements WaitGroupInterface $this->done(); } } - } catch (\Throwable) {} finally { + } catch (\Throwable) { + } finally { $this->_count = 0; } - } /** @inheritdoc */ public function add(int $delta = 1): bool { - $this->_count ++; + $this->_count++; + return true; } /** @inheritdoc */ public function done(): bool { - $this->_count --; + $this->_count--; + return true; } diff --git a/docs/files/src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php.txt b/docs/files/src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php.txt index a75e293..3c7ade6 100644 --- a/docs/files/src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php.txt +++ b/docs/files/src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php.txt @@ -9,7 +9,7 @@ namespace Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers; class SwooleWaitGroup implements WaitGroupInterface { - /** @var int */ + /** @var int */ protected int $_count; /** @inheritdoc */ @@ -28,23 +28,25 @@ class SwooleWaitGroup implements WaitGroupInterface $this->done(); } } - } catch (\Throwable) {} finally { + } catch (\Throwable) { + } finally { $this->_count = 0; } - } /** @inheritdoc */ public function add(int $delta = 1): bool { - $this->_count ++; + $this->_count++; + return true; } /** @inheritdoc */ public function done(): bool { - $this->_count --; + $this->_count--; + return true; } @@ -65,7 +67,7 @@ class SwooleWaitGroup implements WaitGroupInterface if ($this->_count <= 0) { return; } - usleep(max((int)($timeout * 1000 * 1000), 0)); + usleep(max((int) ($timeout * 1000 * 1000), 0)); } } } diff --git a/docs/files/src/Utils/WaitGroup/Handlers/SwowWaitGroup.php.txt b/docs/files/src/Utils/WaitGroup/Handlers/SwowWaitGroup.php.txt index fd96f04..187749d 100644 --- a/docs/files/src/Utils/WaitGroup/Handlers/SwowWaitGroup.php.txt +++ b/docs/files/src/Utils/WaitGroup/Handlers/SwowWaitGroup.php.txt @@ -11,7 +11,7 @@ use Swow\Sync\WaitGroup; class SwowWaitGroup implements WaitGroupInterface { - /** @var WaitGroup */ + /** @var WaitGroup */ protected WaitGroup $_waitGroup; /** @var int 计数 */ @@ -34,7 +34,8 @@ class SwowWaitGroup implements WaitGroupInterface $this->done(); } } - } catch (\Throwable) {} finally { + } catch (\Throwable) { + } finally { $this->_count = 0; } } @@ -43,7 +44,8 @@ class SwowWaitGroup implements WaitGroupInterface public function add(int $delta = 1): bool { $this->_waitGroup->add($delta); - $this->_count ++; + $this->_count++; + return true; } @@ -51,7 +53,8 @@ class SwowWaitGroup implements WaitGroupInterface public function done(): bool { $this->_waitGroup->done(); - $this->_count --; + $this->_count--; + return true; } @@ -64,6 +67,6 @@ class SwowWaitGroup implements WaitGroupInterface /** @inheritdoc */ public function wait(int|float $timeout = -1): void { - $this->_waitGroup->wait($timeout > 0 ? (int)($timeout * 1000) : $timeout); + $this->_waitGroup->wait($timeout > 0 ? (int) ($timeout * 1000) : $timeout); } } diff --git a/docs/files/src/Utils/WaitGroup/Handlers/WaitGroupInterface.php.txt b/docs/files/src/Utils/WaitGroup/Handlers/WaitGroupInterface.php.txt index 8a17046..2484c40 100644 --- a/docs/files/src/Utils/WaitGroup/Handlers/WaitGroupInterface.php.txt +++ b/docs/files/src/Utils/WaitGroup/Handlers/WaitGroupInterface.php.txt @@ -48,4 +48,4 @@ interface WaitGroupInterface * @return void */ public function wait(int|float $timeout = -1): void; -} \ No newline at end of file +} diff --git a/docs/files/src/Utils/WaitGroup/WaitGroup.php.txt b/docs/files/src/Utils/WaitGroup/WaitGroup.php.txt index a22b8c1..b41b94b 100644 --- a/docs/files/src/Utils/WaitGroup/WaitGroup.php.txt +++ b/docs/files/src/Utils/WaitGroup/WaitGroup.php.txt @@ -10,6 +10,7 @@ namespace Workbunny\WebmanCoroutine\Utils\WaitGroup; use Workbunny\WebmanCoroutine\Factory; use Workbunny\WebmanCoroutine\Utils\RegisterMethods; use Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers\DefaultWaitGroup; +use Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers\RevoltWaitGroup; use Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers\RippleWaitGroup; use Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers\SwooleWaitGroup; use Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers\SwowWaitGroup; @@ -38,8 +39,9 @@ class WaitGroup Factory::WORKBUNNY_SWOW => SwowWaitGroup::class, Factory::WORKERMAN_SWOOLE => SwooleWaitGroup::class, Factory::WORKBUNNY_SWOOLE => SwooleWaitGroup::class, - Factory::REVOLT_FIBER => RippleWaitGroup::class, + Factory::REVOLT_FIBER => RevoltWaitGroup::class, Factory::RIPPLE_FIBER => RippleWaitGroup::class, + Factory::RIPPLE_FIBER_5 => RippleWaitGroup::class ]; /** @@ -82,6 +84,7 @@ class WaitGroup if (!method_exists($this->_interface, $name)) { throw new \BadMethodCallException("Method $name not exists. "); } + return $this->_interface->$name(...$arguments); } -} \ No newline at end of file +} diff --git a/docs/files/src/Utils/Worker/AbstractWorker.php.txt b/docs/files/src/Utils/Worker/AbstractWorker.php.txt index d01c827..37e924a 100644 --- a/docs/files/src/Utils/Worker/AbstractWorker.php.txt +++ b/docs/files/src/Utils/Worker/AbstractWorker.php.txt @@ -14,7 +14,6 @@ use Workerman\Worker; abstract class AbstractWorker extends Worker { - /** @inheritDoc */ protected static function initWorkers() { diff --git a/docs/files/src/Utils/Worker/ServerMethods.php.txt b/docs/files/src/Utils/Worker/ServerMethods.php.txt index ea790b5..bf8d5f5 100644 --- a/docs/files/src/Utils/Worker/ServerMethods.php.txt +++ b/docs/files/src/Utils/Worker/ServerMethods.php.txt @@ -9,10 +9,20 @@ namespace Workbunny\WebmanCoroutine\Utils\Worker; use Workbunny\WebmanCoroutine\Utils\Coroutine\Coroutine; use Workbunny\WebmanCoroutine\Utils\WaitGroup\WaitGroup; + +use function Workbunny\WebmanCoroutine\wait_for; + use Workerman\Connection\ConnectionInterface; trait ServerMethods { + /** + * 请求消费者协程数量,0为无限 + * + * @var int + */ + public static int $consumerCount = 0; + /** * 每个连接的协程计数 * @@ -67,6 +77,21 @@ trait ServerMethods : (static::$_connectionCoroutineCount[$connectionId] ?? 0); } + /** + * 回收连接的协程计数 + * + * @param string $connectionId + * @param bool $force + * @return void + */ + public static function unsetConnectionCoroutineCount(string $connectionId, bool $force = false): void + { + if (!$force and self::getConnectionCoroutineCount($connectionId) > 0) { + return; + } + unset(static::$_connectionCoroutineCount[$connectionId]); + } + /** * @link parent::$onConnect * @return null|callable @@ -149,22 +174,35 @@ trait ServerMethods } else { call_user_func($this->getParentOnClose(), $connection); } + self::unsetConnectionCoroutineCount(spl_object_hash($connection), true); }; } + // 保证只调用一次 + $consumerCount = static::$consumerCount; // 代理onMessage if ($this->onMessage) { $this->_parentOnMessage = $this->onMessage; - $this->onMessage = function (ConnectionInterface $connection, mixed $data, ...$params) { + $this->onMessage = function (ConnectionInterface $connection, mixed $data, ...$params) use ($consumerCount) { $connectionId = spl_object_hash($connection); $res = null; $params = func_get_args(); + if ($consumerCount > 0) { + // 等待协程消费者回收 + wait_for(function () use ($connectionId, $consumerCount) { + return self::getConnectionCoroutineCount($connectionId) <= $consumerCount; + }); + } $waitGroup = new WaitGroup(); $waitGroup->add(); // 协程创建 new Coroutine(function () use (&$res, $waitGroup, $params, $connectionId) { - $res = call_user_func($this->getParentOnMessage(), ...$params); - self::$_connectionCoroutineCount[$connectionId] --; - $waitGroup->done(); + try { + $res = call_user_func($this->getParentOnMessage(), ...$params); + } finally { + self::$_connectionCoroutineCount[$connectionId]--; + self::unsetConnectionCoroutineCount($connectionId); + $waitGroup->done(); + } }); self::$_connectionCoroutineCount[$connectionId] = (isset(self::$_connectionCoroutineCount[$connectionId]) @@ -172,9 +210,9 @@ trait ServerMethods : 1); // 等待 $waitGroup->wait(); + return $res; }; } } - } diff --git a/docs/files/src/Utils/Worker/WorkerMethods.php.txt b/docs/files/src/Utils/Worker/WorkerMethods.php.txt index 423b340..55b9889 100644 --- a/docs/files/src/Utils/Worker/WorkerMethods.php.txt +++ b/docs/files/src/Utils/Worker/WorkerMethods.php.txt @@ -12,7 +12,6 @@ use Workbunny\WebmanCoroutine\Utils\WaitGroup\WaitGroup; trait WorkerMethods { - /** * @var callable|null */ @@ -67,5 +66,4 @@ trait WorkerMethods $waitGroup->wait(-1); }; } - } diff --git a/docs/files/src/Utils/tools.php.txt b/docs/files/src/Utils/tools.php.txt index 9192590..39dcf6c 100644 --- a/docs/files/src/Utils/tools.php.txt +++ b/docs/files/src/Utils/tools.php.txt @@ -22,10 +22,10 @@ function add_class_annotations(string $targetClass, string $sourceClass): void if (str_starts_with($method->getName(), '__')) { continue; } - $params = array_map(function($param) { - return $param->getType() . " $" . $param->getName(); + $params = array_map(function ($param) { + return $param->getType() . ' $' . $param->getName(); }, $method->getParameters()); - $annotations[] = "@method " . $method->getReturnType() . " " . $method->getName() . "(" . implode(', ', $params) . ")"; + $annotations[] = '@method ' . $method->getReturnType() . ' ' . $method->getName() . '(' . implode(', ', $params) . ')'; } $annotationString = "/**\n * " . implode("\n * ", $annotations) . "\n */\n"; diff --git a/docs/files/src/helpers.php.txt b/docs/files/src/helpers.php.txt index b0aa603..255d956 100644 --- a/docs/files/src/helpers.php.txt +++ b/docs/files/src/helpers.php.txt @@ -8,6 +8,7 @@ declare(strict_types=1); namespace Workbunny\WebmanCoroutine; // 设置环境变量 +use Composer\InstalledVersions; use Workbunny\WebmanCoroutine\Handlers\HandlerInterface; putenv('WORKBUNNY_COROUTINE=1'); @@ -21,6 +22,7 @@ putenv('WORKBUNNY_COROUTINE=1'); function event_loop(?string $expectEventLoopClass = null): string { Factory::init($expectEventLoopClass); + return Factory::getCurrentEventLoop(); } @@ -52,13 +54,7 @@ function wait_for(?\Closure $closure, float|int $timeout = -1): void */ function package_installed(string $packageName): bool { - $composerFile = dirname(__DIR__) . '/composer.json'; - if (!file_exists($composerFile)) { - return false; - } - $composerData = json_decode(file_get_contents($composerFile), true); - - return isset($composerData['require'][$packageName]); + return InstalledVersions::isInstalled($packageName); } /** diff --git a/docs/indices/files.html b/docs/indices/files.html index 032a494..d31c62b 100644 --- a/docs/indices/files.html +++ b/docs/indices/files.html @@ -123,11 +123,21 @@

                              H

                              -

                              R

                              +

                              P

                              + +

                              R

                              diff --git a/docs/namespaces/workbunny-webmancoroutine-utils-channel-handlers.html b/docs/namespaces/workbunny-webmancoroutine-utils-channel-handlers.html index 87a4a90..0ca2bd3 100644 --- a/docs/namespaces/workbunny-webmancoroutine-utils-channel-handlers.html +++ b/docs/namespaces/workbunny-webmancoroutine-utils-channel-handlers.html @@ -123,7 +123,7 @@

                              -
                              DefaultChannel
                              RippleChannel
                              SwooleChannel
                              SwowChannel
                              +
                              DefaultChannel
                              RevoltChannel
                              RippleChannel
                              SwooleChannel
                              SwowChannel
                              diff --git a/docs/namespaces/workbunny-webmancoroutine-utils-coroutine-handlers.html b/docs/namespaces/workbunny-webmancoroutine-utils-coroutine-handlers.html index 600e761..af3f14e 100644 --- a/docs/namespaces/workbunny-webmancoroutine-utils-coroutine-handlers.html +++ b/docs/namespaces/workbunny-webmancoroutine-utils-coroutine-handlers.html @@ -123,7 +123,7 @@

                              -
                              DefaultCoroutine
                              RippleCoroutine
                              SwooleCoroutine
                              SwowCoroutine
                              +
                              DefaultCoroutine
                              RevoltCoroutine
                              RippleCoroutine
                              SwooleCoroutine
                              SwowCoroutine
                              diff --git a/docs/namespaces/workbunny-webmancoroutine-utils-pool.html b/docs/namespaces/workbunny-webmancoroutine-utils-pool.html new file mode 100644 index 0000000..a15fb8e --- /dev/null +++ b/docs/namespaces/workbunny-webmancoroutine-utils-pool.html @@ -0,0 +1,267 @@ + + + + + Documentation + + + + + + + + + + + + + + + + + + + + + +
                              +

                              Documentation

                              + + + + + +
                              + +
                              +
                              + + + + +
                              +
                              + + +
                              +

                              Pool

                              + + +

                              + Table of Contents + + +

                              + + + + +

                              + Classes + + +

                              +
                              +
                              Pool
                              + + + + + + + + + + + +
                              +
                              +
                              +
                              +
                              
                              +        
                              + +
                              +
                              + + + +
                              +
                              +
                              + +
                              + On this page + +
                                +
                              • Table Of Contents
                              • +
                              • + +
                              • + + +
                              +
                              + +
                              +
                              +
                              +
                              +
                              +

                              Search results

                              + +
                              +
                              +
                                +
                                +
                                +
                                +
                                + + +
                                + + + + + + + + diff --git a/docs/namespaces/workbunny-webmancoroutine-utils-waitgroup-handlers.html b/docs/namespaces/workbunny-webmancoroutine-utils-waitgroup-handlers.html index 19aa5a3..4e362c5 100644 --- a/docs/namespaces/workbunny-webmancoroutine-utils-waitgroup-handlers.html +++ b/docs/namespaces/workbunny-webmancoroutine-utils-waitgroup-handlers.html @@ -123,7 +123,7 @@

                                -
                                DefaultWaitGroup
                                RippleWaitGroup
                                SwooleWaitGroup
                                SwowWaitGroup
                                +
                                DefaultWaitGroup
                                RevoltWaitGroup
                                RippleWaitGroup
                                SwooleWaitGroup
                                SwowWaitGroup
                                diff --git a/docs/namespaces/workbunny-webmancoroutine-utils.html b/docs/namespaces/workbunny-webmancoroutine-utils.html index 2a314ab..3241e62 100644 --- a/docs/namespaces/workbunny-webmancoroutine-utils.html +++ b/docs/namespaces/workbunny-webmancoroutine-utils.html @@ -114,6 +114,7 @@

                                Channel
                                Coroutine
                                +
                                Pool
                                WaitGroup
                                Worker
                                diff --git a/docs/namespaces/workbunny-webmancoroutine.html b/docs/namespaces/workbunny-webmancoroutine.html index 9b35d91..11e6a90 100644 --- a/docs/namespaces/workbunny-webmancoroutine.html +++ b/docs/namespaces/workbunny-webmancoroutine.html @@ -185,9 +185,9 @@

                                根据环境加载event-loop

                                @@ -232,9 +232,9 @@

                                等待回调执行返回true

                                @@ -294,9 +294,9 @@

                                判断是否composer安装了指定包

                                @@ -341,9 +341,9 @@

                                判断是否在workbunny协程环境

                                diff --git a/docs/packages/WebmanCoroutine.html b/docs/packages/WebmanCoroutine.html index 0261c92..edd29eb 100644 --- a/docs/packages/WebmanCoroutine.html +++ b/docs/packages/WebmanCoroutine.html @@ -119,7 +119,7 @@

                                -
                                CoroutineWebServer
                                协程化web服务进程
                                SwooleEvent
                                SwowEvent
                                EventLoopException
                                事件循环异常
                                HandlerException
                                处理器异常
                                RuntimeException
                                SkipWaitGroupDoneException
                                特殊异常类,用于跳过 WaitGroup的done,用于特殊情况的阻塞
                                WorkerException
                                Factory
                                工厂化启动器
                                DefaultHandler
                                默认处理器,使用workerman基础事件
                                RippleHandler
                                基于Ripple插件的协程处理器,支持PHP-fiber
                                RippleWorkerman5Handler
                                基于Ripple插件的协程处理器,支持PHP-fiber
                                SwooleHandler
                                基于swoole实现的协程处理器
                                SwooleWorkerman5Handler
                                基于swoole实现的Workerman5.x版本协程处理器
                                SwowHandler
                                基于swow实现的协程处理器
                                SwowWorkerman5Handler
                                基于swow实现的Workerman5.X的协程处理器
                                Channel
                                DefaultChannel
                                RippleChannel
                                SwooleChannel
                                SwowChannel
                                Coroutine
                                DefaultCoroutine
                                RippleCoroutine
                                SwooleCoroutine
                                SwowCoroutine
                                DefaultWaitGroup
                                RippleWaitGroup
                                SwooleWaitGroup
                                SwowWaitGroup
                                WaitGroup
                                AbstractWorker
                                Server
                                网络进程
                                Worker
                                普通进程
                                +
                                CoroutineWebServer
                                协程化web服务进程
                                SwooleEvent
                                SwowEvent
                                EventLoopException
                                事件循环异常
                                HandlerException
                                处理器异常
                                PoolException
                                RuntimeException
                                SkipWaitGroupDoneException
                                特殊异常类,用于跳过 WaitGroup的done,用于特殊情况的阻塞
                                WorkerException
                                Factory
                                工厂化启动器
                                DefaultHandler
                                默认处理器,使用workerman基础事件
                                RevoltHandler
                                基于Ripple插件的协程处理器,支持PHP-fiber
                                RippleHandler
                                基于Ripple插件的协程处理器,支持PHP-fiber
                                RippleWorkerman5Handler
                                基于Ripple插件的协程处理器,支持PHP-fiber
                                SwooleHandler
                                基于swoole实现的协程处理器
                                SwooleWorkerman5Handler
                                基于swoole实现的Workerman5.x版本协程处理器
                                SwowHandler
                                基于swow实现的协程处理器
                                SwowWorkerman5Handler
                                基于swow实现的Workerman5.X的协程处理器
                                Channel
                                DefaultChannel
                                RevoltChannel
                                RippleChannel
                                SwooleChannel
                                SwowChannel
                                Coroutine
                                DefaultCoroutine
                                RevoltCoroutine
                                RippleCoroutine
                                SwooleCoroutine
                                SwowCoroutine
                                Pool
                                DefaultWaitGroup
                                RevoltWaitGroup
                                RippleWaitGroup
                                SwooleWaitGroup
                                SwowWaitGroup
                                WaitGroup
                                AbstractWorker
                                Server
                                网络进程
                                Worker
                                普通进程

                                Traits @@ -127,7 +127,7 @@

                                -
                                RegisterMethods
                                ServerMethods
                                WorkerMethods
                                +
                                HandlerMethods
                                RegisterMethods
                                ServerMethods
                                WorkerMethods
                                @@ -193,9 +193,9 @@

                                根据环境加载event-loop

                                @@ -240,9 +240,9 @@

                                等待回调执行返回true

                                @@ -302,9 +302,9 @@

                                判断是否composer安装了指定包

                                @@ -349,9 +349,9 @@

                                判断是否在workbunny协程环境