webman2.1支持了协程,文档里数据库这节,写到“每个进程有自己的连接池,进程间不共享连接池。”
webman 1版本时,数据库启动是在onWorkerStart里里加载LaravelDb.php,从而启动数据库,每个进程一个数据库连接。
1、请教社区大牛,2.1版本是怎么做到每个进程有自己的连接池,进程间不共享连接池的?源码看不懂,有没有大牛帮忙解析分析一下关键代码。
2、文档提到,当使用Swoole Swow Fiber驱动时,workerman每次运行onWorkerStart onMessage onConnect onClose等回调时会自动创建一个协程来执行。源码中Worker.php中
public function run(): void
{
$this->listen();
if (!$this->onWorkerStart) {
return;
}
// Try to emit onWorkerStart callback.
$callback = function() {
try {
($this->onWorkerStart)($this);
} catch (Throwable $e) {
// Avoid rapid infinite loop exit.
sleep(1);
static::stopAll(250, $e);
}
};
switch (Worker::$eventLoopClass) {
case Swoole::class:
case Swow::class:
case Fiber::class:
Coroutine::create($callback);
break;
default:
(new \Fiber($callback))->start();
}
}
只有run方法中的onWorkerStart回调中新建了协程,没有看到其他回调中新建协程,请大佬指教!!!
谢谢!!!