初始化代码
This commit is contained in:
30
application/admin/model/ReloadDb.php
Normal file
30
application/admin/model/ReloadDb.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user