30 lines
591 B
PHP
30 lines
591 B
PHP
<?php
|
|
|
|
|
|
namespace app\admin\model;
|
|
|
|
|
|
use think\Db;
|
|
|
|
class ReloadDb
|
|
{
|
|
private static $time = null;
|
|
|
|
/**
|
|
* 检测或执行主动重连
|
|
* @author andy3513
|
|
* @param int $timeout 超时时间
|
|
* @param array $config 连接参数
|
|
*/
|
|
public static function init($timeout = 7200,$config = []){
|
|
$time = time();
|
|
if(null === self::$time){
|
|
self::$time = $time;
|
|
}
|
|
$exprie = $time - self::$time;
|
|
if($exprie >= $timeout){
|
|
Db::connect($config, true);
|
|
self::$time = $time;
|
|
}
|
|
}
|
|
} |