webman怎么在onWorkerStart中實例化數(shù)據(jù)庫?以保證每個進程只需要連接一次數(shù)據(jù)庫即可,降低數(shù)據(jù)庫連接數(shù)
在這個目錄 support\bootstrap
use Webman\Bootstrap;
class ThinkOrm implements Bootstrap
{
/**
* @param $worker
* @return mixed|void
*/
public static function start($worker){
// 配置
Db::setConfig(config('thinkorm'));
// 維持mysql心跳
if ($worker) {
Timer::add(55, function () {
$connections = config('thinkorm.connections', []);
foreach ($connections as $key => $item) {
if ($item['type'] == 'mysql') {
Db::connect($key)->query('select 1');
}
}
});
}
}
}
然后在 config/bootstrap 文件
return [
\support\bootstrap\ThinkOrm::class,
];