hyperf-chat/app/Bootstrap/ServerStart.php

45 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2020-11-07 22:57:10 +08:00
<?php
2021-09-11 12:41:28 +08:00
declare(strict_types=1);
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
*/
2021-04-20 16:30:57 +08:00
2020-11-07 22:57:10 +08:00
namespace App\Bootstrap;
2021-05-21 22:56:42 +08:00
use App\Cache\ServerRunID;
2020-11-07 22:57:10 +08:00
use Hyperf\Framework\Bootstrap\ServerStartCallback;
2020-11-08 17:10:05 +08:00
use Swoole\Timer;
2020-11-07 22:57:10 +08:00
/**
* 自定义服务启动前回调事件
*
* @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
{
2021-05-21 22:56:42 +08:00
ServerRunID::getInstance()->add(SERVER_RUN_ID, time());
2020-11-07 22:57:10 +08:00
}
2020-11-08 17:10:05 +08:00
}