This commit is contained in:
2021-03-02 18:33:12 +08:00
parent 0eee8d6cff
commit b2fea0250a
4 changed files with 160 additions and 118 deletions
+39
View File
@@ -4,13 +4,17 @@ declare(strict_types=1);
namespace HttpServer\Abstracts;
use Database\Connection;
use Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use ReflectionException;
use Snowflake\Abstracts\Config;
use Snowflake\Error\Logger;
use Snowflake\Event;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
use Swoole\Coroutine\Server;
use Swoole\Timer;
@@ -132,4 +136,39 @@ abstract class Callback extends HttpService
}
}
/**
* @throws ConfigException
* @throws ComponentException
* @throws Exception
*/
protected function clearMysqlClient()
{
$databases = Config::get('databases', false, []);
if (empty($databases)) {
return;
}
$application = Snowflake::app();
foreach ($databases as $name => $database) {
/** @var Connection $connection */
$connection = $application->get('databases.' . $name, false);
if (empty($connection)) {
continue;
}
$connection->disconnect();
}
}
/**
* @throws ConfigException
* @throws ComponentException
* @throws Exception
*/
protected function clearRedisClient()
{
$redis = Snowflake::app()->getRedis();
$redis->destroy();
}
}