hyperf-chat/app/Bootstrap/ServerStart.php

39 lines
767 B
PHP
Raw Normal View History

2020-11-07 22:57:10 +08:00
<?php
namespace App\Bootstrap;
use Hyperf\Framework\Bootstrap\ServerStartCallback;
2020-11-08 17:10:05 +08:00
use Swoole\Timer;
use Hyperf\Redis\Redis;
2020-11-07 22:57:10 +08:00
/**
* 自定义服务启动前回调事件
*
* Class ServerStart
* @package App\Bootstrap
*/
class ServerStart extends ServerStartCallback
{
/**
* 回调事件
*/
public function beforeStart()
{
2020-11-08 17:10:05 +08:00
stdout_log()->info(sprintf('服务运行ID : %s', SERVER_RUN_ID));
2020-11-07 22:57:10 +08:00
2020-11-27 19:48:41 +08:00
// 维护服务运行状态
2020-11-29 14:44:11 +08:00
$this->setRunIdTime();
2020-11-08 17:10:05 +08:00
Timer::tick(15000, function () {
2020-11-29 14:44:11 +08:00
$this->setRunIdTime();
2020-11-08 17:10:05 +08:00
});
}
2020-11-07 22:57:10 +08:00
2020-11-29 14:44:11 +08:00
/**
* 更新运行ID时间
*/
public function setRunIdTime()
2020-11-08 17:10:05 +08:00
{
container()->get(Redis::class)->hset('SERVER_RUN_ID', SERVER_RUN_ID, time());
2020-11-07 22:57:10 +08:00
}
2020-11-08 17:10:05 +08:00
}