Db.php 718 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace think\swoole\pool;
  3. use think\Config;
  4. use think\db\ConnectionInterface;
  5. use think\swoole\pool\proxy\Connection;
  6. /**
  7. * Class Db
  8. * @package think\swoole\pool
  9. * @property Config $config
  10. */
  11. class Db extends \think\Db
  12. {
  13. protected function createConnection(string $name): ConnectionInterface
  14. {
  15. return new Connection(function () use ($name) {
  16. return parent::createConnection($name);
  17. }, $this->config->get('swoole.pool.db', []));
  18. }
  19. protected function getConnectionConfig(string $name): array
  20. {
  21. $config = parent::getConnectionConfig($name);
  22. //打开断线重连
  23. $config['break_reconnect'] = true;
  24. return $config;
  25. }
  26. }