webman2.1支持了協(xié)程,文檔里數(shù)據(jù)庫這節(jié),寫到“每個進程有自己的連接池,進程間不共享連接池?!?/p>
webman 1版本時,數(shù)據(jù)庫啟動是在onWorkerStart里里加載LaravelDb.php,從而啟動數(shù)據(jù)庫,每個進程一個數(shù)據(jù)庫連接。
1、請教社區(qū)大牛,2.1版本是怎么做到每個進程有自己的連接池,進程間不共享連接池的?源碼看不懂,有沒有大牛幫忙解析分析一下關鍵代碼。
2、文檔提到,當使用Swoole Swow Fiber驅(qū)動時,workerman每次運行onWorkerStart onMessage onConnect onClose等回調(diào)時會自動創(chuàng)建一個協(xié)程來執(zhí)行。源碼中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回調(diào)中新建了協(xié)程,沒有看到其他回調(diào)中新建協(xié)程,請大佬指教?。。?br /> 謝謝?。?!
你可以這么理解,每個進程的數(shù)據(jù)是隔離的,除非你使用Workbunny\WebmanSharedCache\Cache; 之類的共享緩存。
所以你應該考慮下PHP多進程下所有數(shù)據(jù)都是共享的會不會出問題。