2020-11-07 22:57:10 +08:00
|
|
|
<?php
|
2020-12-26 21:33:40 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* This is my open source code, please do not use it for commercial applications.
|
|
|
|
*
|
|
|
|
* For the full copyright and license information,
|
|
|
|
* please view the LICENSE file that was distributed with this source code
|
|
|
|
*
|
|
|
|
* @author Yuandong<837215079@qq.com>
|
|
|
|
* @link https://github.com/gzydong/hyperf-chat
|
|
|
|
*/
|
2020-11-07 22:57:10 +08:00
|
|
|
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
|
|
|
}
|