-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEasySwooleEvent.php
61 lines (48 loc) · 1.73 KB
/
EasySwooleEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace EasySwoole\EasySwoole;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\FileWatcher\FileWatcher;
use EasySwoole\FileWatcher\WatchRule;
use EasySwoole\ORM\Db\Config as ConfigAlias;
use EasySwoole\ORM\Db\Connection;
use EasySwoole\ORM\DbManager;
class EasySwooleEvent implements Event
{
public static function initialize()
{
date_default_timezone_set('Asia/Shanghai');
}
public static function mainServerCreate(EventRegister $register)
{
static::mysqlClient();
static::hotUpdate();
}
/**
* Notes:mysql
* User: Fly
* DateTime: 2022/3/25 21:51
*/
public static function mysqlClient(){
$config = new ConfigAlias();
$config->setDatabase('bb');
$config->setUser('bb');
$config->setPassword('123456');
$config->setHost('192.168.43.219');
$config->setPort(3306);
$config->setTimeout(15); // 超时时间
// 设置指定连接名称 后期可通过连接名称操作不同的数据库
DbManager::getInstance()->addConnection(new Connection($config),'write');
DbManager::getInstance()->addConnection(new Connection($config),'read');
}
public static function hotUpdate(){
$watcher = new FileWatcher();
$rule = new WatchRule(EASYSWOOLE_ROOT . "/App"); // 设置监控规则和监控目录
$watcher->addRule($rule);
$watcher->setOnChange(function () {
Logger::getInstance()->info('file change ,reload!!!');
ServerManager::getInstance()->getSwooleServer()->reload();
});
$watcher->attachServer(ServerManager::getInstance()->getSwooleServer());
}
}