Commit 44ddb35f authored by cuiweifeng's avatar cuiweifeng

update : 增加destoryConnect cli

parent b9d4473a
......@@ -173,6 +173,10 @@ abstract class MysqlBase
*/
public static function getConnection($type, $flush = false)
{
if(PHP_SAPI == 'cli'){
// cli模式下,不走单例,gone away
$flush = true;
}
if (!isset(self::$dbConnect[static::CONFIG_INDEX.':'.$type]) || $flush) {
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = new Medoo(self::getDbConf($type));
}
......@@ -495,4 +499,20 @@ abstract class MysqlBase
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
return self::$dbConnect[static::CONFIG_INDEX.':'.$type]->action($actions);
}
/**
* 销毁所有已存在的连接,守护进程需要手动调用
*
* @return void
*/
public static function destroyConnetion()
{
if(self::$dbConnect) {
foreach(self::$dbConnect as $conn) {
$conn->pdo = null;
unset($conn);
}
self::$dbConnect = [];
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment