手冊有異步mysql示例,更多的示例還要慢慢補充
http://doc3.workerman.net/component/reactmysql.html
恩 想請教一個問題
public static function onWorkerStart($BusinessWorker)
{
//mysql
global $asyncMysql;
$loop = $BusinessWorker::getEventLoop();
// 連接參數(shù)
$asyncMysql = new React\MySQL\Connection($loop, array(
'host' => '192.168.1.201', // 不要寫localhost
'dbname' => 'toc_grab',
'user' => 'devuser',
'passwd' => 'devuser',
));
// 出現(xiàn)錯誤時
$asyncMysql->on('error', function($e){
echo $e;
});
// 執(zhí)行連接
$asyncMysql->connect(function ($e) {
if($e) {
echo $e;
} else {
echo "async mysql connect success\n";
}
});
//redis
global $asyncRedis;
$asyncRedis = new Factory($loop);
}
當(dāng) onWorkerStart的時候每個worker進(jìn)程 有一個異步的 mysql和redis的實例,當(dāng)并發(fā)請求多的時候 每個進(jìn)程中異步的mysql 和redis 都是公用同一個連接會不會對性能有影響?