Skip to content

Commit

Permalink
doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Oct 10, 2024
1 parent dcdb36d commit 8e3b2c9
Show file tree
Hide file tree
Showing 101 changed files with 8,766 additions and 606 deletions.
51 changes: 34 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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开发带来一些帮助,甚至灵感。

## 安装

Expand All @@ -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 配置文件
Expand All @@ -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`
Expand All @@ -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) |

## ♨️ 相关文章

Expand Down
28 changes: 14 additions & 14 deletions docs/classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ <h4 class="phpdocumentor-element__name" id="method_getConnectionCoroutineCount">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/CoroutineWebServer.php"><a href="files/src-coroutinewebserver.html"><abbr title="src/CoroutineWebServer.php">CoroutineWebServer.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">36</span>
<span class="phpdocumentor-element-found-in__line">35</span>

<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.36" class="phpdocumentor-element-found-in__source" data-line="36" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.35" class="phpdocumentor-element-found-in__source" data-line="35" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
</aside>

<p class="phpdocumentor-summary">获取连接的协程计数</p>
Expand Down Expand Up @@ -282,9 +282,9 @@ <h4 class="phpdocumentor-element__name" id="method_onClose">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/CoroutineWebServer.php"><a href="files/src-coroutinewebserver.html"><abbr title="src/CoroutineWebServer.php">CoroutineWebServer.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">116</span>
<span class="phpdocumentor-element-found-in__line">115</span>

<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.116" class="phpdocumentor-element-found-in__source" data-line="116" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.115" class="phpdocumentor-element-found-in__source" data-line="115" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
</aside>

<p class="phpdocumentor-summary">连接关闭</p>
Expand Down Expand Up @@ -339,9 +339,9 @@ <h4 class="phpdocumentor-element__name" id="method_onConnect">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/CoroutineWebServer.php"><a href="files/src-coroutinewebserver.html"><abbr title="src/CoroutineWebServer.php">CoroutineWebServer.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">94</span>
<span class="phpdocumentor-element-found-in__line">93</span>

<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.94" class="phpdocumentor-element-found-in__source" data-line="94" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.93" class="phpdocumentor-element-found-in__source" data-line="93" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
</aside>

<p class="phpdocumentor-summary">连接建立</p>
Expand Down Expand Up @@ -396,9 +396,9 @@ <h4 class="phpdocumentor-element__name" id="method_onMessage">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/CoroutineWebServer.php"><a href="files/src-coroutinewebserver.html"><abbr title="src/CoroutineWebServer.php">CoroutineWebServer.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">138</span>
<span class="phpdocumentor-element-found-in__line">137</span>

<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.138" class="phpdocumentor-element-found-in__source" data-line="138" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.137" class="phpdocumentor-element-found-in__source" data-line="137" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
</aside>


Expand Down Expand Up @@ -480,9 +480,9 @@ <h4 class="phpdocumentor-element__name" id="method_onWorkerStart">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/CoroutineWebServer.php"><a href="files/src-coroutinewebserver.html"><abbr title="src/CoroutineWebServer.php">CoroutineWebServer.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">59</span>
<span class="phpdocumentor-element-found-in__line">58</span>

<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.59" class="phpdocumentor-element-found-in__source" data-line="59" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.58" class="phpdocumentor-element-found-in__source" data-line="58" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
</aside>


Expand Down Expand Up @@ -539,9 +539,9 @@ <h4 class="phpdocumentor-element__name" id="method_onWorkerStop">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/CoroutineWebServer.php"><a href="files/src-coroutinewebserver.html"><abbr title="src/CoroutineWebServer.php">CoroutineWebServer.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">78</span>
<span class="phpdocumentor-element-found-in__line">77</span>

<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.78" class="phpdocumentor-element-found-in__source" data-line="78" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.77" class="phpdocumentor-element-found-in__source" data-line="77" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
</aside>

<p class="phpdocumentor-summary">停止服务</p>
Expand Down Expand Up @@ -596,9 +596,9 @@ <h4 class="phpdocumentor-element__name" id="method_unsetConnectionCoroutineCount
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/CoroutineWebServer.php"><a href="files/src-coroutinewebserver.html"><abbr title="src/CoroutineWebServer.php">CoroutineWebServer.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">50</span>
<span class="phpdocumentor-element-found-in__line">49</span>

<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.50" class="phpdocumentor-element-found-in__source" data-line="50" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-CoroutineWebServer.html#source-view.49" class="phpdocumentor-element-found-in__source" data-line="49" data-modal="source-view" data-src="files/src/CoroutineWebServer.php.txt"></a>
</aside>

<p class="phpdocumentor-summary">回收连接的协程计数</p>
Expand Down
20 changes: 10 additions & 10 deletions docs/classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ <h4 class="phpdocumentor-element__name" id="method_clearAllTimer">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/Events/SwooleEvent.php"><a href="files/src-events-swooleevent.html"><abbr title="src/Events/SwooleEvent.php">SwooleEvent.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">184</span>
<span class="phpdocumentor-element-found-in__line">209</span>

<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.184" class="phpdocumentor-element-found-in__source" data-line="184" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.209" class="phpdocumentor-element-found-in__source" data-line="209" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
</aside>


Expand Down Expand Up @@ -427,9 +427,9 @@ <h4 class="phpdocumentor-element__name" id="method_del">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/Events/SwooleEvent.php"><a href="files/src-events-swooleevent.html"><abbr title="src/Events/SwooleEvent.php">SwooleEvent.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">103</span>
<span class="phpdocumentor-element-found-in__line">128</span>

<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.103" class="phpdocumentor-element-found-in__source" data-line="103" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.128" class="phpdocumentor-element-found-in__source" data-line="128" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
</aside>


Expand Down Expand Up @@ -493,9 +493,9 @@ <h4 class="phpdocumentor-element__name" id="method_destroy">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/Events/SwooleEvent.php"><a href="files/src-events-swooleevent.html"><abbr title="src/Events/SwooleEvent.php">SwooleEvent.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">170</span>
<span class="phpdocumentor-element-found-in__line">195</span>

<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.170" class="phpdocumentor-element-found-in__source" data-line="170" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.195" class="phpdocumentor-element-found-in__source" data-line="195" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
</aside>


Expand Down Expand Up @@ -542,9 +542,9 @@ <h4 class="phpdocumentor-element__name" id="method_getTimerCount">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/Events/SwooleEvent.php"><a href="files/src-events-swooleevent.html"><abbr title="src/Events/SwooleEvent.php">SwooleEvent.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">193</span>
<span class="phpdocumentor-element-found-in__line">220</span>

<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.193" class="phpdocumentor-element-found-in__source" data-line="193" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.220" class="phpdocumentor-element-found-in__source" data-line="220" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
</aside>


Expand Down Expand Up @@ -591,9 +591,9 @@ <h4 class="phpdocumentor-element__name" id="method_loop">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/Events/SwooleEvent.php"><a href="files/src-events-swooleevent.html"><abbr title="src/Events/SwooleEvent.php">SwooleEvent.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">161</span>
<span class="phpdocumentor-element-found-in__line">186</span>

<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.161" class="phpdocumentor-element-found-in__source" data-line="161" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
<a href="classes/Workbunny-WebmanCoroutine-Events-SwooleEvent.html#source-view.186" class="phpdocumentor-element-found-in__source" data-line="186" data-modal="source-view" data-src="files/src/Events/SwooleEvent.php.txt"></a>
</aside>


Expand Down
Loading

0 comments on commit 8e3b2c9

Please sign in to comment.