hyperf-chat/app/Bootstrap/ServerStart.php

37 lines
737 B
PHP

<?php
namespace App\Bootstrap;
use App\Support\Packet;
use App\Support\SocketIOParser;
use Hyperf\Framework\Bootstrap\ServerStartCallback;
use Swoole\Timer;
use Hyperf\Redis\Redis;
/**
* 自定义服务启动前回调事件
*
* Class ServerStart
* @package App\Bootstrap
*/
class ServerStart extends ServerStartCallback
{
/**
* 回调事件
*/
public function beforeStart()
{
stdout_log()->info(sprintf('服务运行ID : %s', SERVER_RUN_ID));
$this->setTimeOut();
Timer::tick(15000, function () {
$this->setTimeOut();
});
}
public function setTimeOut()
{
container()->get(Redis::class)->hset('SERVER_RUN_ID', SERVER_RUN_ID, time());
}
}